开发者

How to Properly Hash a String

开发者 https://www.devze.com 2023-01-06 01:19 出处:网络
Will the following function correctly hash my provided string? Or am I missing something fundamentally important?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号