简体   繁体   中英

A VB.NET equivalent of a PHP hash function

I am having trouble converting this PHP code to VB.

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

I have this VB code

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. The password was encrypted using the PHP code above.

Can anyone help me with this? Very much appreciated. Thank you.

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

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

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