1

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.

1 Answer 1

1

The php hash function returns the data encoded in hexadecimal not base64.

Return BitConverter.ToString(pwdh).Replace("-", "")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.