Reputation: 887
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.
Upvotes: 1
Views: 667
Reputation: 22433
The php hash function returns the data encoded in hexadecimal not base64.
Return BitConverter.ToString(pwdh).Replace("-", "")
Upvotes: 1