1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| public static string HashPassword(string password, int saltSize, int iterations)
{
if (password == null) throw new ArgumentNullException("password");
byte[] salt;
byte[] bytes;
using (Rfc2898DeriveBytes rfc2898DeriveBytes = new Rfc2898DeriveBytes(password, saltSize, iterations))
{
salt = rfc2898DeriveBytes.Salt;
bytes = rfc2898DeriveBytes.GetBytes(32);
}
byte[] inArray = new byte[saltSize + 32];
Buffer.BlockCopy((Array)salt, 0, (Array)inArray, 0, saltSize);
Buffer.BlockCopy((Array)bytes, 0, (Array)inArray, saltSize, 32);
return Convert.ToBase64String(inArray);
} |
Partager