开发者

Why don't HashBytes and MD5CryptoServiceProvider().ComputeHash match?

开发者 https://www.devze.com 2023-03-25 19:53 出处:网络
Can someone explain to me why don\'t T-SQL\'s SELECT substring(master.dbo.fn_varbintohexstr(hashbytes(\'MD5\', \'HelloWorld\')), 3, 32)

Can someone explain to me why don't T-SQL's

SELECT substring(master.dbo.fn_varbintohexstr(hashbytes('MD5', 'HelloWorld')), 3, 32)

and .NET's

Convert.ToBase64String(New Sys开发者_StackOverflowtem.Security.Cryptography.MD5CryptoServiceProvider().ComputeHash(System.Text.Encoding.UTF8.GetBytes("HelloWorld")))

return the same result?

Tsql returns 68e109f0f40ca72a15e05cc22786f8e6 and .net returns aOEJ8PQMpyoV4FzCJ4b45g==


The .net one is base64, the T-SQL one is hex. They are different encodings.

The length of the output tells you that too because MD5 delivers 16 bytes (as per the T-SQL solution)


Because you are asking T-SQL to return the bytes HEX encoded while you tell .NET to return them Base64-encoded... that are very different encoding and do never match...

0

精彩评论

暂无评论...
验证码 换一张
取 消