Created
September 19, 2012 05:46
-
-
Save jamesottaway/3747884 to your computer and use it in GitHub Desktop.
.NET CryptSharp PBKDF2 with HMACSHA512
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
var password = "password"; | |
var salt = "saltsalt"; | |
var iterations = 50000; | |
var passwordBytes = System.Text.Encoding.UTF8.GetBytes(password); | |
var saltBytes = System.Text.Encoding.UTF8.GetBytes(salt); | |
var hashSize = new System.Security.Cryptography.HMACSHA512().HashSize / 8; | |
var hashedPassword = new byte[hashSize]; | |
var sha512Callback = CryptSharp.Utility.Pbkdf2.CallbackFromHmac<System.Security.Cryptography.HMACSHA512>(); | |
var sha512pbkdf2 = new CryptSharp.Utility.Pbkdf2(passwordBytes, saltBytes, iterations, sha512Callback, hashSize); | |
sha512pbkdf2.Read(hashedPassword); | |
Console.WriteLine(Convert.ToBase64String(hashedPassword)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With version 2, it's now:
var algo = new System.Security.Cryptography.HMACSHA512();
byte[] hashedPassword = CryptSharp.Utility.Pbkdf2.ComputeDerivedKey(algo, saltBytes, iterations, hashSize);
Console.WriteLine(System.Convert.ToBase64String(hashedPassword));