tags:

views:

55

answers:

2

Will the following function correctly hash my provided string? Or am I missing something fundamentally important?

Private Function HashString(ByVal value As String, ByVal salt As String) As String

    Dim dataBytes As Byte() = System.Text.Encoding.UTF8.GetBytes(value + salt)
    Dim hash As New System.Security.Cryptography.SHA512Managed
    Dim hashBytes As Byte() = hash.ComputeHash(dataBytes)

    Return Convert.ToBase64String(hashBytes)

End Function
+2  A: 

Looks fine to me. Allowing for a salt is important - though it's still left to the caller to ensure the salt is unique.

Rex M
Seemed a little to easy to be true, especially with so many more complex examples floating around out there. Thank you.
Matt Hanson
+2  A: 

I think you have the best practice in there, namely the salting of the hash. This is very important and often overlooked. Looks good to me.

Ciaran Archer