Secure Hash





6
Date Submitted Wed. Sep. 6th, 2006 9:22 PM
Revision 1 of 1
Helper jbplou
Tags Security | String | VB.NET
Comments 1 comments
This snippet generates a secure hash string using VB.NET


    'generates an 88 character hash string using a SHA1 derived algorithm
    Private Function GenerateHash(ByVal valueToHash As String, ByVal salt As String) As String
        Dim hasher As New System.Security.Cryptography.SHA512Managed
        Dim saltAsByte As Byte() = System.Text.Encoding.UTF8.GetBytes(salt)
        Dim valueToHashAsByte As Byte() = System.Text.Encoding.UTF8.GetBytes(valueToHash)
        Dim valueToHashPlusSaltAsByte(saltAsByte.Length + valueToHashAsByte.Length) As Byte
        saltAsByte.CopyTo(valueToHashPlusSaltAsByte, 0)
        valueToHashAsByte.CopyTo(valueToHashPlusSaltAsByte, saltAsByte.Length)
        Dim returnBytes As Byte() = hasher.ComputeHash(valueToHashPlusSaltAsByte)
        hasher.Clear()
        Return Convert.ToBase64String(returnBytes)
    End Function

 

Jeff B

Comments

Comments Better version
Thu. Sep. 7th, 2006 7:20 PM    Helper jbplou

Voting