Пример #1
0
        /// <summary>
        /// Version 1: Derives an key from the specified password.
        /// </summary>
        /// <param name="password">The password.</param>
        /// <param name="bcryptSalt">bCrypt salt (16 bytes).</param>
        /// <param name="pbkdf2Salt">PBKDF2 salt (min 8 bytes)</param>
        /// <param name="workload">bCrypt workload (4 - 31).</param>
        /// <param name="keySize">The size of the key to derive (bits).</param>
        /// <returns>Key.</returns>
        static byte[] DeriveKeyV1(string password, byte[] bcryptSalt, byte[] pbkdf2Salt, int workload, int keySize)
        {
            var bcryptKey = BC.Crypt(password, bcryptSalt, workload);

            using (var deriveKey = new Rfc2898DeriveBytes(bcryptKey, pbkdf2Salt, 10000))
            {
                return(deriveKey.GetBytes(keySize >> 3));
            }
        }