public static SymmetricAlgorithm GetSymmetricAlgorithm(string algorithm) { var symmetric = null as SymmetricAlgorithm; if (AesEncryption.Contains(algorithm)) { symmetric = Aes.Create(); } if (symmetric == null) { throw new NotSupportedException($"Encryption algorithm '{algorithm}' not supported."); } symmetric.Mode = GetCipherMode(algorithm); symmetric.Padding = PaddingMode.ISO10126; symmetric.KeySize = GetKeySize(algorithm); symmetric.GenerateKey(); symmetric.GenerateIV(); return(symmetric); }