コード例 #1
0
        public override ICryptoTransform CreateEncryptor(byte[] key, byte[] iv)
        {
            Contract.Ensures(Contract.Result <ICryptoTransform>() != null);

            if (key == null)
            {
                throw new ArgumentNullException("key");
            }
            if (!ValidKeySize(key.Length * 8))
            {
                throw new ArgumentException(SR.GetString(SR.Cryptography_InvalidKeySize), "key");
            }
            if (iv != null && iv.Length * 8 != BlockSizeValue)
            {
                throw new ArgumentException(SR.GetString(SR.Cryptography_InvalidIVSize), "iv");
            }

            byte[] keyCopy = (byte[])key.Clone();
            byte[] ivCopy  = null;
            if (iv != null)
            {
                ivCopy = (byte[])iv.Clone();
            }

            using (SafeCapiKeyHandle importedKey = CapiNative.ImportSymmetricKey(m_cspHandle, GetAlgorithmId(keyCopy.Length * 8), keyCopy)) {
                return(CreateEncryptor(importedKey, ivCopy));
            }
        }
コード例 #2
0
 public override ICryptoTransform CreateEncryptor(byte[] key, byte[] iv)
 {
     if (key == null)
     {
         throw new ArgumentNullException("key");
     }
     if (!base.ValidKeySize(key.Length * 8))
     {
         throw new ArgumentException(System.SR.GetString("Cryptography_InvalidKeySize"), "key");
     }
     if ((iv != null) && ((iv.Length * 8) != base.BlockSizeValue))
     {
         throw new ArgumentException(System.SR.GetString("Cryptography_InvalidIVSize"), "iv");
     }
     byte[] buffer  = (byte[])key.Clone();
     byte[] buffer2 = null;
     if (iv != null)
     {
         buffer2 = (byte[])iv.Clone();
     }
     using (SafeCapiKeyHandle handle = CapiNative.ImportSymmetricKey(this.m_cspHandle, GetAlgorithmId(buffer.Length * 8), buffer))
     {
         return(this.CreateEncryptor(handle, buffer2));
     }
 }