Tommykent1210
Tommykent1210

Reputation: 39

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

Upvotes: 3

Views: 1708

Answers (1)

alundy
alundy

Reputation: 857

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.

Upvotes: 1

Related Questions