/// <summary> /// Decrypts a byte array encrypted using <see cref="Encrypt(string,byte[],string,int,int,out SymmetricKey)" />. /// </summary> /// <param name="rsaKey">The decrypting RSA key as XML or as a secure key container name.</param> /// <param name="cipherText">The encrypted data.</param> /// <returns>The decrypted data.</returns> /// <exception cref="CryptographicException">Thrown is the encrypted data block is incorrectly formatted.</exception> public static byte[] Decrypt(string rsaKey, byte[] cipherText) { SymmetricKey symmetricKey = null; try { return(Decrypt(rsaKey, cipherText, out symmetricKey)); } finally { if (symmetricKey != null) { symmetricKey.Dispose(); } } }
/// <summary> /// Encrypts a byte array using a combination of an asymmetric RSA key and the /// specified symmetric encryption algorithm and a one-time key generated by /// the method. /// </summary> /// <param name="rsaKey">The encrypting RSA key as XML or as a secure key container name.</param> /// <param name="plainText">The data to be encrypted.</param> /// <param name="algorithm">The symmetric encryption algorithm name.</param> /// <param name="keySize">The one-time symmetric key size to generate in bits.</param> /// <param name="paddedSize">Specifies the minimum padded size of the encrypted content.</param> /// <returns>The encrypted result.</returns> /// <remarks> /// <para> /// The current supported cross platform encryption algorithms /// are: "DES", "RC2", "TripleDES", and "AES" (Rijndael). /// </para> /// </remarks> /// <exception cref="ArgumentException">Thrown if the requested encryption algorithm is unknown.</exception> public static byte[] Encrypt(string rsaKey, byte[] plainText, string algorithm, int keySize, int paddedSize) { SymmetricKey symmetricKey = null; try { return(Encrypt(rsaKey, plainText, algorithm, keySize, paddedSize, out symmetricKey)); } finally { if (symmetricKey != null) { symmetricKey.Dispose(); } } }