Last active
December 19, 2015 17:09
-
-
Save mclasson/5989543 to your computer and use it in GitHub Desktop.
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 static HashedPassword Generate(string password) | |
{ | |
byte[] _salt = new byte[8]; | |
using (RNGCryptoServiceProvider csp = new RNGCryptoServiceProvider()) | |
{ | |
csp.GetBytes(_salt); | |
} | |
byte[] _password = System.Text.Encoding.UTF8.GetBytes(password); | |
Rfc2898DeriveBytes k1 = new Rfc2898DeriveBytes(_password, _salt, 10000); | |
var _saltedPasswordHash = k1.GetBytes(24); | |
return new HashedPassword() | |
{ | |
Password = Convert.ToBase64String(_saltedPasswordHash), | |
Salt = Convert.ToBase64String(_salt) | |
}; | |
} | |
public struct HashedPassword | |
{ | |
public string Password { get; set; } | |
public string Salt { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment