コード例 #1
0
        private static SymmetricAlgorithm CreateSymmetricAlgorithm(ICryptographicCredentials cryptographicCredentials)
        {
            var symmetricAlgorithm = SymmetricAlgorithm.Create(cryptographicCredentials.SymmetricAlgorithm);

            symmetricAlgorithm.Key = cryptographicCredentials.Key.ToArray();
            symmetricAlgorithm.IV  = cryptographicCredentials.InitialVector.ToArray();

            return(symmetricAlgorithm);
        }
コード例 #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();
            }
            ;
        }
コード例 #3
0
 private async Task <T> CreateSymmetricAlgorithm <T>(ICryptographicCredentials cryptographicCredentials, Func <SymmetricAlgorithm, Task <T> > action)
 {
     return(await DisposableHelper.UseAsync(async (symmetricAlgorithm) => await action(symmetricAlgorithm),
                                            () => CreateSymmetricAlgorithm(cryptographicCredentials)).ConfigureAwait(false));;
 }
コード例 #4
0
 public async Task <IEnumerable <byte> > Encrypt(ICryptographicCredentials cryptographicCredentials, string value)
 {
     return(await CreateSymmetricAlgorithm(cryptographicCredentials,
                                           async (symmetricAlgorithm) => await Encrypt(value, symmetricAlgorithm)).ConfigureAwait(false));
 }