public static (string password, byte[] salt) generate_hash(string password, int rounds = 20) { var pwBytes = Hex.IsHex(password) ? Hex.FromHex(password) : Encoding.Default.GetBytes(password); var saltBytes = generate_salt(); var pwHashBytes = scr.Generate(pwBytes, saltBytes, 262144 / 4, rounds, 1, 512); return(Convert.ToBase64String(pwHashBytes), saltBytes); }
public static bool validate_password(string password, string hash, byte[] salt, int rounds = 20) { var pwBytes = Hex.IsHex(password) ? Hex.FromHex(password) : Encoding.Default.GetBytes(password); var pwHashBytes = scr.Generate(pwBytes, salt, 262144 / 4, rounds, 1, 512); var hashBytes = Convert.FromBase64String(hash); return(pwHashBytes.SequenceEqual(hashBytes)); }