Пример #1
0
        // wraps the supplied input key data using the provided symmetric algorithm
        public static byte[] EncryptKey(byte[] keyData, KeyParameter symmetricAlgorithm)
        {
            if (keyData == null)
            {
                throw new ArgumentNullException(nameof(keyData));
            }
            if (symmetricAlgorithm == null)
            {
                throw new ArgumentNullException(nameof(symmetricAlgorithm));
            }

            if (symmetricAlgorithm is DesParameters)
            {
                // CMS Triple DES Key Wrap
                return(SymmetricKeyWrap.TripleDESKeyWrapEncrypt(symmetricAlgorithm.GetKey(), keyData));
            }
            else
            {
                // FIPS AES Key Wrap
                return(SymmetricKeyWrap.AESKeyWrapEncrypt(symmetricAlgorithm.GetKey(), keyData));
            }
        }
Пример #2
0
        // decrypts the supplied wrapped key using the provided symmetric algorithm
        public static byte[] DecryptKey(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.TripleDESKeyWrapDecrypt(symmetricAlgorithm.Key, keyData));
            }
            else if (symmetricAlgorithm is Rijndael || symmetricAlgorithm is Aes)
            {
                // FIPS AES Key Wrap
                return(SymmetricKeyWrap.AESKeyWrapDecrypt(symmetricAlgorithm.Key, keyData));
            }
            // throw an exception if the transform is not in the previous categories
            throw new System.Security.Cryptography.CryptographicException(SR.Cryptography_Xml_NotSupportedCryptographicTransform);
        }