private static SymmetricAlgorithm CreateSymmetricAlgorithm(ICryptographicCredentials cryptographicCredentials) { var symmetricAlgorithm = SymmetricAlgorithm.Create(cryptographicCredentials.SymmetricAlgorithm); symmetricAlgorithm.Key = cryptographicCredentials.Key.ToArray(); symmetricAlgorithm.IV = cryptographicCredentials.InitialVector.ToArray(); return(symmetricAlgorithm); }
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(); } ; }
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));; }
public async Task <IEnumerable <byte> > Encrypt(ICryptographicCredentials cryptographicCredentials, string value) { return(await CreateSymmetricAlgorithm(cryptographicCredentials, async (symmetricAlgorithm) => await Encrypt(value, symmetricAlgorithm)).ConfigureAwait(false)); }