简体   繁体   中英

Unexpected MD5 hash result between PHP and VB.NET

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

I just ran your exact code and got 5e9000c4f54e403484889df696151b9c , so your input string must not be exactly equal to A3f4yoJz .

Update: Mark's comments to your question are probably the way to go. Double-check the input string for whitespace.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM