using System.Security.Cryptography;
private const int HashIterations = 2000;
public static void Main()
var password = "testpassword";
var salt = "VZEBR0IPTlQsN9A+uI48i9uYJkJBhjZla2nW9e1i8ZeSaEO96wenAVU/R3WcNojS5ZLhGX9xFHyqIJjVKIlm7bSQWjL/v1oB9R6IPspmG2LmiQEAMPujlZOpLXg/e5iykT6bTCSuJkpIUOLhf6XuK800WWWF+aiYppuoFj9gk7k3WFT7aLcAUVinEjueXLFobkABm545Jcj6lQtK8HMhLNYA5HTB6ac557SN/XzsM1UjpTuX18FrdvoxlogW5Qg==";
var hash = GeneratePasswordHash(password, salt);
public static string GeneratePasswordHash(string password, string salt, int hashIterations = HashIterations)
using (var crypto = new Rfc2898DeriveBytes(password, Convert.FromBase64String(salt), hashIterations, HashAlgorithmName.SHA256))
hash = crypto.GetBytes(64);
return Convert.ToBase64String(hash);
public static byte[] GeneratePasswordHash()
using (var randomNumberGenerator = new RNGCryptoServiceProvider())
randomNumberGenerator.GetBytes(salt);