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
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