public static bool Verify(string password, byte[] salt, int iteration, byte[] key) { BytesEx passwordBytes = BytesEx.FromString(password); BytesEx saltBytes = BytesEx.FromBytes(salt); BytesEx keyBytes = BytesEx.FromBytes(key); Pbkdf2Result pbkdf2 = new Pbkdf2Result(passwordBytes, saltBytes, iteration, keyBytes); return(Verify(pbkdf2)); }
public static bool Verify(Pbkdf2Result pbkdf2) { byte[] passwordBytes = pbkdf2.Password.Values; byte[] saltBytes = pbkdf2.Salt.Values; int iteration = pbkdf2.Iteration; int keyLength = pbkdf2.Key.Values.Length; Rfc2898DeriveBytes hasher = new Rfc2898DeriveBytes(passwordBytes, saltBytes, iteration); byte[] keyBytes = hasher.GetBytes(keyLength); return(pbkdf2.Key.Equals(keyBytes)); }
public static Pbkdf2Result Hash(string password, int?saltLength, int?iteration, int?keyLength) { Pbkdf2Parameter parameter = new Pbkdf2Parameter(); parameter.Password = BytesEx.FromString(password); parameter.SaltLength = saltLength; parameter.Iteration = iteration; parameter.KeyLength = keyLength; Pbkdf2Result pbkdf2 = Hash(parameter); return(pbkdf2); }
public static Pbkdf2Result Hash(Pbkdf2Parameter parameter) { if (parameter == null || parameter.Password == null) { throw new ArgumentNullException(); } if (parameter.Salt == null && parameter.SaltLength == null) { parameter.SaltLength = 16; } byte[] passwordBytes = parameter.Password.Values; byte[] saltBytes = parameter.SaltLength.HasValue ? RandomExpress.RandomizeBytes(parameter.SaltLength.Value) : parameter.Salt.Values; int iteration = parameter.Iteration ?? 17; int keyLength = parameter.KeyLength ?? 16; Rfc2898DeriveBytes hasher = new Rfc2898DeriveBytes(passwordBytes, saltBytes, iteration); byte[] keyBytes = hasher.GetBytes(keyLength); Pbkdf2Result pbkdf2 = new Pbkdf2Result(passwordBytes, saltBytes, iteration, keyBytes); return(pbkdf2); }