AesCng::CreateEncryptor Method (array<Byte>^, array<Byte>^)
Creates a symmetric AES encryptor object with the specified key and initialization vector (IV).
Assembly: System.Core (in System.Core.dll)
public: virtual ICryptoTransform^ CreateEncryptor( array<unsigned char>^ rgbKey, array<unsigned char>^ rgbIV ) override
Parameters
- rgbKey
-
Type:
array<System::Byte>^
The secret key to use for the AES algorithm. The key size must be 128, 192, or 256 bits.
- rgbIV
-
Type:
array<System::Byte>^
The initialization vector to use for the AES algorithm.
| Exception | Condition |
|---|---|
| ArgumentNullException | rgbKey is null. |
| ArgumentException | rgbKey is not a valid size for this algorithm. -or- rgbIV size does not match the block size for this algorithm. |
| CryptographicException | rgbKey is a known weak key for this algorithm and cannot be used. -or- rgbIV is null. |
Use this method to encrypt a message and then use the CreateDecryptor overload with the same signature to decrypt the result of this method.
Note |
|---|
If you've created the AesCng object using an existing persisted key and you want to make use of that key when encrypting the message, you want to set the IV property and then call the parameterless CreateEncryptor() overload instead; otherwise, using this method will create an ephemeral key as specified by the rgbKey parameter. |
Available since 4.6.2
