Skip to content

Instantly share code, notes, and snippets.

@Hafthor
Created May 13, 2012 02:36
Show Gist options
  • Save Hafthor/2670635 to your computer and use it in GitHub Desktop.
Save Hafthor/2670635 to your computer and use it in GitHub Desktop.
CalculatePasswordHash
Public Function CalculatePasswordHash(password As String, usernameOrId As String) As Byte()
Static saltBytes = New Byte() {&HDE, &HAD, &HC0, &HDE}
Static h As New SHA512CryptoServiceProvider
Dim o(0 To h.HashSize \ 8 - 1) As Byte
Dim usrBytes = UTF8Encoding.UTF8.GetBytes(usernameOrId)
Dim pwdBytes = UTF8Encoding.UTF8.GetBytes(password)
SyncLock h
h.Initialize()
h.TransformBlock(usrBytes, 0, usrBytes.Length, o, 0)
h.TransformBlock(saltBytes, 0, saltBytes.Length, o, 0)
h.TransformFinalBlock(pwdBytes, 0, pwdBytes.Length)
Return h.Hash
End SyncLock
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment