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...
精彩评论