How to convert CryptHashData to .Net MD5CryptoServiceProvider?

T

Tino

Hello All,

I am trying to re-write an old functionality that we used in a Borland C++
application usung the CryptHashData Windows function. It works good so far
but I am having trouble getting the same hash value if I am using a salt.

Here is what we did in the old software:
CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);
CryptCreateHash(hProv, CALG_MD5, 0, 0, &hHash);
CryptHashData(hHash, pbData, SaltLength, 0); // add the salt to the hash
(salt is in pbData)
CryptHashData(hHash, pSourceString.c_str(), pSourceString.Length(), 0); //
hash the source string
CryptGetHashParam(hHash, HP_HASHVAL, rgbHash, &cbHash, 0); // retrieve the
hash

.... worked - as said - beautifully.
Now I am doing:

HashAlgorithm md5 = new MD5CryptoServiceProvider();
result = md5.ComputeHash(encoding.GetBytes(tbSource.Text));

....like a dream! It gives the same hash value if I am not using any salt in
the first algorithm. But now if I am using salt, how can I do that with
MD5CryptoServiceProvider? I thought I could just add it to the source string
but that gives me a different hash.

Certainly there is a way - I just can't get my head around it.

Any help highly appreciated!

Best Regards,
Tino
 
T

Tino

Sorry for posting the same message twice. I got an error when I sent it the
first time.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top