简体   繁体   中英

Equivalent md5 hash for PHP and vb.NET 2008

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim source As String = TextBox1.Text
    Using md5Hash As MD5 = MD5.Create()
        Dim hash As String = GetMd5Hash(md5Hash, source)
        TextBox2.Text = hash
    End Using
End Sub

I've used the above code generate a md5 of 32 characters. The md5 for "1234567" is given as fcea920f7412b5da7be0cf42b8c93759 but I want the md5 hash to be generated as d38f0d62daf542c5f10d8f29adacae17 as it is generated by md5() function of PHP.

How do I generate equivalent md5 hash in VB.NET?

Encoding is the problem. Encoding that you are using in VB.NET to generate hash is different from what is used by PHP. You must use the same encoding that the PHP uses while generating the hash from VB.NET. It could be like:

Dim BytesArray() As Byte
BytesArray = System.Text.Encoding.UTF8.GetBytes("Your Input String)

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