Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Sql MD5 hash doesn't match C# MD5 hash

Author  Topic 

WaterWolf
Starting Member

24 Posts

Posted - 2009-03-27 : 07:36:26
Hello,

I have a field in my database that contains a MD5 hash that was generated in c#. The code that generated it:


public string ComputeHash(string str)
{
private static readonly HashAlgorithm _hashProvider = new MD5CryptoServiceProvider();

byte[] hash = _hashProvider.ComputeHash(_encoding.GetBytes(str));

StringBuilder sbHashCode = new StringBuilder();
foreach (byte theByte in hash) {
sbHashCode.AppendFormat("{0:X}", theByte);
}
return sbHashCode.ToString();
}


I have tried to generate the same hash using sql server:

SELECT HashBytes('MD5', Value) FROM tTable


However the two hashes generated from the same string do not match. Does anybody know what I may be doing wrong for the hashes not to match?

nzmike
Starting Member

21 Posts

Posted - 2009-04-15 : 00:19:44
Hi,

I was wondering if you solved this? I'm having an identical problem as you so would love to know what the solution is if you know!

Thanks,

Mike
Go to Top of Page
   

- Advertisement -