0
select cast(hashbytes('md5', 'test') as varchar)

displays

載쵫ⅆ珓�荎✦

but in C#,

System.Security.Cryptography.MD5.ComputeHash('test');

displays

c8059e2ec7419f590e79d7f1b774bfe6

which looks to be correct. Is this a problem with SQL Server's encoding?

divided
  • 1,249
  • 5
  • 14
  • 27

1 Answers1

2

hashbytes is getting the raw MD5, while C# is returning the base-16 encoded version. (In fact, ComputeHash does the same thing -- you had to do some form of conversion to get it into that base 16 string, didn't you? :) )

Billy ONeal
  • 104,103
  • 58
  • 317
  • 552
  • I suppose I did. How can I display the base-16 encoded version in SQL Server? – divided Jan 03 '11 at 16:56
  • @divided: Unfortunately, I don't know. I don't think you even can without writing the base 16 stuff yourself -- luckily it's easy to do but I don't know Transact enough to be able to write such. – Billy ONeal Jan 03 '11 at 16:59