简体   繁体   English

PHP和vb.NET 2008的等效md5哈希

[英]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. 我用上面的代码生成了32个字符的md5。 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. “1234567”的md5以fcea920f7412b5da7be0cf42b8c93759给出,但我希望md5哈希生成为d38f0d62daf542c5f10d8f29adacae17,因为它是由PHP的md5()函数生成的。

How do I generate equivalent md5 hash in VB.NET? 如何在VB.NET中生成等效的md5哈希?

Encoding is the problem. 编码是个问题。 Encoding that you are using in VB.NET to generate hash is different from what is used by PHP. 您在VB.NET中使用的编码生成散列与PHP使用的编码不同。 You must use the same encoding that the PHP uses while generating the hash from VB.NET. 您必须使用与从VB.NET生成哈希时PHP使用的相同编码。 It could be like: 它可能像:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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