开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜