我已经尝试使用MD5在PHP中散列一个字符串,在C#中也是如此,但结果是不同的...有人可以解释我如何匹配它吗?
我的C#代码看起来像
md5 = new MD5CryptoServiceProvider();
originalBytes = ASCIIEncoding.Default.GetBytes(AuthCode);
encodedBytes = md5.ComputeHash(originalBytes);
Guid r = new Guid(encodedBytes);
string hashString = r.ToString("N");
Run Code Online (Sandbox Code Playgroud)
提前致谢
编辑:我的字符串是一个字符串123
输出;
PHP:202cb962ac59075b964b07152d234b70
C#:62b92c2059ac5b07964b07152d234b70
Jul*_*iet 37
你的问题在这里:
Guid r = new Guid(encodedBytes);
string hashString = r.ToString("N");
Run Code Online (Sandbox Code Playgroud)
我不确定为什么要将编码的字节加载到Guid中,但这不是将字节转换回字符串的正确方法.BitConverter
改为使用:
string testString = "123";
byte[] asciiBytes = ASCIIEncoding.ASCII.GetBytes(testString);
byte[] hashedBytes = MD5CryptoServiceProvider.Create().ComputeHash(asciiBytes);
string hashedString = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
// hashString == 202cb962ac59075b964b07152d234b70
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
13487 次 |
最近记录: |