public static bool VerifyPasswordPbkdf2(string plain, HashAndSalt hashed) { byte[] newHash = KeyDerivation.Pbkdf2( password: plain, salt: hashed.Salt, prf: KeyDerivationPrf.HMACSHA256, iterationCount: IterCount, numBytesRequested: HashLenght ); return(SlowEquals(hashed.PasswordHash, newHash)); }
public static HashAndSalt FromBytes(byte[] bytes) { var res = new HashAndSalt() { Salt = new byte[PasswordHelper.SaltLength], PasswordHash = new byte[PasswordHelper.HashLenght] }; Array.Copy(bytes, res.PasswordHash, PasswordHelper.HashLenght); Array.Copy(bytes, PasswordHelper.HashLenght, res.Salt, 0, PasswordHelper.SaltLength); return(res); }
public static HashAndSalt HashPasswordPbkdf2(string password) { var res = new HashAndSalt(); var rng = RandomNumberGenerator.Create(); res.Salt = new byte[SaltLength]; rng.GetBytes(res.Salt); res.PasswordHash = KeyDerivation.Pbkdf2( password: password, salt: res.Salt, prf: KeyDerivationPrf.HMACSHA256, iterationCount: IterCount, numBytesRequested: HashLenght ); return(res); }
public static bool VerifyPasswordPbkdf2(string plain, byte[] hashed) { return(VerifyPasswordPbkdf2(plain, HashAndSalt.FromBytes(hashed))); }
public static bool VerifyPasswordPbkdf2(string plain, string hashed) { return(VerifyPasswordPbkdf2(plain, HashAndSalt.FromString(hashed))); }