// wraps the supplied input key data using the provided symmetric algorithm public static byte[] EncryptKey(byte[] keyData, SymmetricAlgorithm symmetricAlgorithm) { if (keyData == null) { throw new ArgumentNullException(nameof(keyData)); } if (symmetricAlgorithm == null) { throw new ArgumentNullException(nameof(symmetricAlgorithm)); } if (symmetricAlgorithm is TripleDES) { // CMS Triple DES Key Wrap return(SymmetricKeyWrap.TripleDESKeyWrapEncrypt(symmetricAlgorithm.Key, keyData)); } #pragma warning disable SYSLIB0022 // Rijndael types are obsolete else if (symmetricAlgorithm is Rijndael || symmetricAlgorithm is Aes) #pragma warning restore SYSLIB0022 { // FIPS AES Key Wrap return(SymmetricKeyWrap.AESKeyWrapEncrypt(symmetricAlgorithm.Key, keyData)); } // throw an exception if the transform is not in the previous categories throw new CryptographicException(SR.Cryptography_Xml_NotSupportedCryptographicTransform); }
public static byte[] EncryptKey(byte[] keyData, SymmetricAlgorithm symmetricAlgorithm) { if (keyData == null) { throw new ArgumentNullException("keyData"); } if (symmetricAlgorithm == null) { throw new ArgumentNullException("symmetricAlgorithm"); } if (symmetricAlgorithm is TripleDES) { return(SymmetricKeyWrap.TripleDESKeyWrapEncrypt(symmetricAlgorithm.Key, keyData)); } if (!(symmetricAlgorithm is Rijndael) && !(symmetricAlgorithm is Aes)) { throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_NotSupportedCryptographicTransform")); } return(SymmetricKeyWrap.AESKeyWrapEncrypt(symmetricAlgorithm.Key, keyData)); }
public static byte[] EncryptKey(byte[] keyData, SymmetricAlgorithm symAlg) { if (keyData == null) { throw new ArgumentNullException("keyData"); } if (symAlg == null) { throw new ArgumentNullException("symAlg"); } if (symAlg is TripleDES) { return(SymmetricKeyWrap.TripleDESKeyWrapEncrypt(symAlg.Key, keyData)); } if (symAlg is Rijndael) { return(SymmetricKeyWrap.AESKeyWrapEncrypt(symAlg.Key, keyData)); } throw new CryptographicException("The specified cryptographic transform is not supported."); }
// wraps the supplied input key data using the provided symmetric algorithm public static byte[] EncryptKey(byte[] keyData, SymmetricAlgorithm symmetricAlgorithm) { if (keyData == null) { throw new ArgumentNullException("keyData"); } if (symmetricAlgorithm == null) { throw new ArgumentNullException("symmetricAlgorithm"); } if (symmetricAlgorithm is TripleDES) { // CMS Triple DES Key Wrap return(SymmetricKeyWrap.TripleDESKeyWrapEncrypt(symmetricAlgorithm.Key, keyData)); } else if (symmetricAlgorithm is Rijndael || symmetricAlgorithm is Aes) { // FIPS AES Key Wrap return(SymmetricKeyWrap.AESKeyWrapEncrypt(symmetricAlgorithm.Key, keyData)); } // throw an exception if the transform is not in the previous categories throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_NotSupportedCryptographicTransform")); }