Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Security > MD5CryptoServiceProvider (ported from CryptHashData)

Reply
Thread Tools

MD5CryptoServiceProvider (ported from CryptHashData)

 
 
Tino
Guest
Posts: n/a
 
      02-10-2009
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to convert CryptHashData to .Net MD5CryptoServiceProvider? Tino ASP .Net Security 1 02-10-2009 02:08 PM
MD5CryptoServiceProvider class Viktor Popov ASP .Net Security 2 09-24-2004 07:26 PM
Generating MD5 hash in ASP that returns same string as .NET MD5CryptoServiceProvider? Derrick ASP General 0 08-23-2004 08:55 PM
System.Security.Cryptography.MD5CryptoServiceProvider Mike ASP .Net Security 1 10-16-2003 02:28 AM



Advertisments