How to Properly Hash a String
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 dataByt开发者_高级运维es 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
Looks fine to me. Allowing for a salt is important - though it's still left to the caller to ensure the salt is unique.
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.
精彩评论