Csharp/C#教程:MD5散列在C#和PHP中不匹配分享


MD5散列在C#和PHP中不匹配

我已经尝试使用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"); 

提前致谢

编辑:我的字符串是123字符串

输出;

PHP:202cb962ac59075b964b07152d234b70

C#:62b92c2059ac5b07964b07152d234b70

你的问题在这里:

 Guid r = new Guid(encodedBytes); string hashString = r.ToString("N"); 

我不确定你为什么要将编码的字节加载到Guid中,但这不是将字节转换回字符串的正确方法。 改为使用BitConverter

上述就是C#学习教程:MD5散列在C#和PHP中不匹配分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

 string testString = "123"; byte[] asciiBytes = ASCIIEncoding.ASCII.GetBytes(testString); byte[] hashedBytes = MD5CryptoServiceProvider.Create().ComputeHash(asciiBytes); string hashedString = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower(); // hashString == 202cb962ac59075b964b07152d234b70 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/1027846.html

(0)
上一篇 2022年1月10日
下一篇 2022年1月10日

精彩推荐