public TCryptographicCredentials GetCryptographicCredentials <TCryptographicCredentials>(KeyDerivationPrf keyDerivationPrf, string password, IEnumerable <byte> salt, int iterations, int totalNumberOfBytes, IEnumerable <byte> initialVector) where TCryptographicCredentials : ICryptographicCredentials
        {
            var key         = _hashingProvider.PasswordDerivedBytes(password, salt, keyDerivationPrf, iterations, totalNumberOfBytes);
            var credentials = GetCryptographicCredentials <TCryptographicCredentials>(Constants.AES, key, initialVector);

            credentials.KeyDerivationPrf   = keyDerivationPrf;
            credentials.Iterations         = iterations;
            credentials.TotalNumberOfBytes = totalNumberOfBytes;
            return(credentials);
        }
Exemplo n.º 2
0
        private async Task <IEnumerable <byte> > Encrypt(EncryptionMethod encryptionMethod,
                                                         ICryptographicCredentials cryptographicCredentials, string value, StringCase @case)
        {
            switch (encryptionMethod)
            {
            case EncryptionMethod.Encryption:
                return(await _cryptographyProvider.Encrypt(cryptographicCredentials, value.Case(@case)));

            case EncryptionMethod.Hashing:
                return(_hashingProvider.PasswordDerivedBytes(value, cryptographicCredentials.Key,
                                                             cryptographicCredentials.KeyDerivationPrf, cryptographicCredentials.Iterations,
                                                             cryptographicCredentials.TotalNumberOfBytes));

            default: throw new NotSupportedException();
            }
            ;
        }