void ComputeHmac(byte[] input, byte[] output) { var hash = new byte[_hmacAlgorithm.GetMacSize()]; _hmacAlgorithm.BlockUpdate(input, 0, input.Length); _hmacAlgorithm.DoFinal(hash, 0); Array.Copy(hash, output, output.Length); }
/// <summary> /// Creates a new PBKDF2 stream. /// </summary> /// <param name="hmacAlgorithm"> /// </param> /// <param name="salt"> /// The salt. /// A unique salt means a unique PBKDF2 stream, even if the original key is identical. /// </param> /// <param name="iterations">The number of iterations to apply.</param> #if USEBC || WINDOWS_UWP || NETCORE public Pbkdf2(nStratis.BouncyCastle.crypto.IMac hmacAlgorithm, byte[] salt, int iterations) { nStratis.Crypto.Cryptsharp.Check.Null("hmacAlgorithm", hmacAlgorithm); nStratis.Crypto.Cryptsharp.Check.Null("salt", salt); nStratis.Crypto.Cryptsharp.Check.Length("salt", salt, 0, int.MaxValue - 4); nStratis.Crypto.Cryptsharp.Check.Range("iterations", iterations, 1, int.MaxValue); int hmacLength = hmacAlgorithm.GetMacSize(); _saltBuffer = new byte[salt.Length + 4]; Array.Copy(salt, _saltBuffer, salt.Length); _iterations = iterations; _hmacAlgorithm = hmacAlgorithm; _digest = new byte[hmacLength]; _digestT1 = new byte[hmacLength]; }