PHP 和 VB.NET 之间出现意外的 MD5 哈希结果
我现在已经尝试了大约 4 个小时,让我的 vb.NET MD5 函数生成与 PHP 相同的哈希值
这是我的 vb.net 函数:
Public Function MD5(ByVal input As String) As String
Dim x As New System.Security.Cryptography.MD5CryptoServiceProvider()
Dim bs As Byte() = System.Text.Encoding.UTF8.GetBytes(input)
bs = x.ComputeHash(bs)
Dim s As New System.Text.StringBuilder()
For Each b As Byte In bs
s.Append(b.ToString("x2").ToLower())
Next
Dim hash As String = s.ToString()
Return hash
End Function
“A3f4yoJz”的 vb.NET MD5 函数产生:
77f366330b7d65d451a96d38009cf06b"
但是 PHP 产生:
5e9000c4f54e403484889df696151b9c
但是,一些 wtrings(例如“paSsword1”)的散列工作得很好。
有什么想法吗?我在vb.net中尝试了多种MD5方法。我无法改变它在 PHP 中的工作方式,因为我正在编写一个库来与商业应用程序交互 - 我只需要生成相同的哈希值!
谢谢,
汤姆
I have been trying now for about 4 hours to get my vb.NET MD5 function to generate the same hash as PHP's
This is my vb.net function:
Public Function MD5(ByVal input As String) As String
Dim x As New System.Security.Cryptography.MD5CryptoServiceProvider()
Dim bs As Byte() = System.Text.Encoding.UTF8.GetBytes(input)
bs = x.ComputeHash(bs)
Dim s As New System.Text.StringBuilder()
For Each b As Byte In bs
s.Append(b.ToString("x2").ToLower())
Next
Dim hash As String = s.ToString()
Return hash
End Function
The vb.NET MD5 function of "A3f4yoJz" produces:
77f366330b7d65d451a96d38009cf06b"
But PHP produces:
5e9000c4f54e403484889df696151b9c
However, the hashing of some wtrings ("paSsword1" for example) work perfectly fine.
Any ideas why? I have tried multiple methods of MD5 in vb.net. I can;t change the way it works in PHP because I'm writing a library to interface with a commercial application - I just need the hashes to be generated the same!
Thanks,
Tom
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我刚刚运行了您的确切代码并得到了
5e9000c4f54e403484889df696151b9c
,因此您的输入字符串不得完全等于A3f4yoJz
。更新:马克对你的问题的评论可能是正确的选择。仔细检查输入字符串中是否有空格。
I just ran your exact code and got
5e9000c4f54e403484889df696151b9c
, so your input string must not be exactly equal toA3f4yoJz
.Update: Mark's comments to your question are probably the way to go. Double-check the input string for whitespace.