예제 #1
0
        public static byte[] ComputeDerivedKey(KeyedHashAlgorithm hmacAlgorithm, byte[] salt, int iterations,
                                               int derivedKeyLength)
        {
            Check.Range("derivedKeyLength", derivedKeyLength, 0, int.MaxValue);

            using (Pbkdf2 kdf = new Pbkdf2(hmacAlgorithm, salt, iterations))
            {
                return(kdf.Read(derivedKeyLength));
            }
        }
예제 #2
0
        /// <summary>
        /// Computes a derived key.
        /// </summary>
        /// <param name="hmacAlgorithm">
        /// </param>
        /// <param name="salt">
        ///     The salt.
        ///     A unique salt means a unique derived key, even if the original key is identical.
        /// </param>
        /// <param name="iterations">The number of iterations to apply.</param>
        /// <param name="derivedKeyLength">The desired length of the derived key.</param>
        /// <returns>The derived key.</returns>
#if USEBC || WINDOWS_UWP || NETCORE
        public static byte[] ComputeDerivedKey(nStratis.BouncyCastle.crypto.IMac hmacAlgorithm, byte[] salt, int iterations,
                                               int derivedKeyLength)
        {
            nStratis.Crypto.Cryptsharp.Check.Range("derivedKeyLength", derivedKeyLength, 0, int.MaxValue);

            using (Pbkdf2 kdf = new Pbkdf2(hmacAlgorithm, salt, iterations))
            {
                return(kdf.Read(derivedKeyLength));
            }
        }
예제 #3
0
        /// <summary>
        /// Computes a derived key.
        /// </summary>
        /// <param name="key">The key to derive from.</param>
        /// <param name="salt">
        ///     The salt.
        ///     A unique salt means a unique SCrypt stream, even if the original key is identical.
        /// </param>
        /// <param name="cost">
        ///     The cost parameter, typically a fairly large number such as 262144.
        ///     Memory usage and CPU time scale approximately linearly with this parameter.
        /// </param>
        /// <param name="blockSize">
        ///     The mixing block size, typically 8.
        ///     Memory usage and CPU time scale approximately linearly with this parameter.
        /// </param>
        /// <param name="parallel">
        ///     The level of parallelism, typically 1.
        ///     CPU time scales approximately linearly with this parameter.
        /// </param>
        /// <param name="maxThreads">
        ///     The maximum number of threads to spawn to derive the key.
        ///     This is limited by the <paramref name="parallel"/> value.
        ///     <c>null</c> will use as many threads as possible.
        /// </param>
        /// <param name="derivedKeyLength">The desired length of the derived key.</param>
        /// <returns>The derived key.</returns>
        public static byte[] ComputeDerivedKey(byte[] key, byte[] salt,
                                               int cost, int blockSize, int parallel, int?maxThreads,
                                               int derivedKeyLength)
        {
            Check.Range("derivedKeyLength", derivedKeyLength, 0, int.MaxValue);

            using (Pbkdf2 kdf = GetStream(key, salt, cost, blockSize, parallel, maxThreads))
            {
                return(kdf.Read(derivedKeyLength));
            }
        }