Created
May 13, 2012 02:36
-
-
Save Hafthor/2670635 to your computer and use it in GitHub Desktop.
CalculatePasswordHash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
http://stackoverflow.com/questions/536584/non-random-salt-for-password-hashes/536756#536756