简体   繁体   English

相当于PHP哈希函数的VB.NET

[英]A VB.NET equivalent of a PHP hash function

I am having trouble converting this PHP code to VB. 我在将此PHP代码转换为VB时遇到麻烦。

$hashpw = hash('sha256', $salt.$password.$salt)

I have this VB code 我有这个VB代码

Public Function HashPassword(ByVal Password As String, ByVal Salt As String) As String
    Dim pwd As String = Salt & Password & Salt
    Dim hasher As New Security.Cryptography.SHA256Managed()
    Dim pwdb As Byte() = System.Text.Encoding.UTF8.GetBytes(pwd)
    Dim pwdh As Byte() = hasher.ComputeHash(pwdb)
    Return Convert.ToBase64String(pwdh)
End Function

but it seems that the password I retrieve from the database is not equivalent to the returned value from the VB code above. 但是我从数据库中检索到的密码似乎不等同于上述VB代码返回的值。 The password was encrypted using the PHP code above. 使用上面的PHP代码对密码进行了加密。

Can anyone help me with this? 谁能帮我这个? Very much appreciated. 非常感谢。 Thank you. 谢谢。

php hash函数返回以十六进制而不是base64编码的数据。

Return BitConverter.ToString(pwdh).Replace("-", "")

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

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