MD5CryptoServiceProvider (ported from CryptHashData)

T

Tino

Hello all,

I am having some problems converting an old Borland C++ program into C# with
..Net. In the old software, we used a salt value to calculate the hash. We did
like this:

CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);
CryptCreateHash(hProv, CALG_MD5, 0, 0, &hHash);

// add salt to the hash (the salt is in phData)
CryptHashData(hHash, pbData, SaltLength, 0);

// hash source string
CryptHashData(hHash, pSourceString.c_str(), pSourceString.Length(), 0);

// retrieve hashed value
CryptGetHashParam(hHash, HP_HASHVAL, rgbHash, &cbHash, 0)

.... it worked like a dream. Now I did:

System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
HashAlgorithm md5 = new MD5CryptoServiceProvider();
byte[] result = md5.ComputeHash(encoding.GetBytes(tbSource.Text));

.... works even better - and gives me the same hash value as long as I am not
using any salt. Now my question is, how do I get the salt value into the hash
with the new .NET - method?

I tried combining the salt with the source string before hashing it but that
gives a different value. How would I do it to get the same result as in the
old method when using a salt?

Thanks in advance and best regards!

Tino
 

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

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top