/// <summary> /// Implements a <see cref="PBKDF2"/> algorthim with a user definded MAC method. /// </summary> /// <param name="method">the HMAC method to use.</param> /// <param name="password">the password to use</param> /// <param name="salt">the salt. Must be at least 64-bit</param> /// <param name="iterations">the number of iterations. Must be at least 1000</param> /// <param name="length">the number of bytes to return</param> /// <returns> /// A salted password based on the specified length. /// </returns> public static byte[] ComputeSaltedPassword(HMACMethod method, byte[] password, byte[] salt, int iterations, int length) { using (var kdf = new PBKDF2(method, password, salt, iterations)) { return(kdf.GetBytes(length)); } }
void TestSHA512(string P, string S, int c, int dkLen, string dk) { byte[] dkExpected = StringToByteArray(dk); using (var pdf = new PBKDF2(HMACMethod.SHA512, Encoding.ASCII.GetBytes(P), Encoding.ASCII.GetBytes(S), c)) { byte[] dkBytes = pdf.GetBytes(dkLen); if (!dkBytes.SequenceEqual(dkExpected)) { throw new Exception(); } } }