2015-05-27 24 views
1

我无法将此PHP代码转换为VB。一个VB.NET等效的PHP哈希函数

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

我有这样的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 

但似乎我从数据库中检索密码是不等同于从上面的VB代码返回值。密码使用上面的PHP代码加密。

任何人都可以帮助我吗? 非常感谢。谢谢。

回答

1

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

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