Пример #1
0
        public SymmetricCryptoKey MakeKeyFromPassword(string password, string salt, KdfType kdf, int kdfIterations)
        {
            if (password == null)
            {
                throw new ArgumentNullException(nameof(password));
            }

            if (salt == null)
            {
                throw new ArgumentNullException(nameof(salt));
            }

            var passwordBytes = Encoding.UTF8.GetBytes(NormalizePassword(password));
            var saltBytes     = Encoding.UTF8.GetBytes(salt);

            byte[] keyBytes = null;
            if (kdf == KdfType.PBKDF2)
            {
                if (kdfIterations < 5000)
                {
                    throw new Exception("PBKDF2 iteration minimum is 5000.");
                }
                keyBytes = _keyDerivationService.DeriveKey(passwordBytes, saltBytes, (uint)kdfIterations);
            }
            else
            {
                throw new Exception("Unknown Kdf.");
            }
            return(new SymmetricCryptoKey(keyBytes));
        }
Пример #2
0
        public byte[] MakeKeyFromPassword(string password, string salt)
        {
            if (password == null)
            {
                throw new ArgumentNullException(nameof(password));
            }

            if (salt == null)
            {
                throw new ArgumentNullException(nameof(salt));
            }

            var passwordBytes = Encoding.UTF8.GetBytes(password);
            var saltBytes     = Encoding.UTF8.GetBytes(salt);

            var key = _keyDerivationService.DeriveKey(passwordBytes, saltBytes, 5000);

            return(key);
        }
Пример #3
0
        public SymmetricCryptoKey MakeKeyFromPassword(string password, string salt)
        {
            if (password == null)
            {
                throw new ArgumentNullException(nameof(password));
            }

            if (salt == null)
            {
                throw new ArgumentNullException(nameof(salt));
            }

            var passwordBytes = Encoding.UTF8.GetBytes(NormalizePassword(password));
            var saltBytes     = Encoding.UTF8.GetBytes(salt);

            var keyBytes = _keyDerivationService.DeriveKey(passwordBytes, saltBytes, 5000);

            return(new SymmetricCryptoKey(keyBytes));
        }