Redigera

Dela via


AesCng.CreateEncryptor Method

Definition

Creates an AES symmetric encryptor object.

Overloads

CreateEncryptor()

Creates a symmetric AES encryptor object using the current key and initialization vector (IV).

CreateEncryptor(Byte[], Byte[])

Creates a symmetric AES encryptor object with the specified key and initialization vector (IV).

CreateEncryptor()

Creates a symmetric AES encryptor object using the current key and initialization vector (IV).

public:
 override System::Security::Cryptography::ICryptoTransform ^ CreateEncryptor();
public override System.Security.Cryptography.ICryptoTransform CreateEncryptor ();
override this.CreateEncryptor : unit -> System.Security.Cryptography.ICryptoTransform
Public Overrides Function CreateEncryptor () As ICryptoTransform

Returns

A symmetric AES encryptor object.

Exceptions

.NET 6 and later: CFB128 mode is selected and the key is persisted.

Remarks

Use this method to encrypt a message and then use the CreateDecryptor overload with the same signature to decrypt the result of this method.

Applies to

CreateEncryptor(Byte[], Byte[])

Source:
Cng.NotSupported.cs
Source:
Cng.NotSupported.cs
Source:
Cng.NotSupported.cs

Creates a symmetric AES encryptor object with the specified key and initialization vector (IV).

public:
 override System::Security::Cryptography::ICryptoTransform ^ CreateEncryptor(cli::array <System::Byte> ^ rgbKey, cli::array <System::Byte> ^ rgbIV);
public override System.Security.Cryptography.ICryptoTransform CreateEncryptor (byte[] rgbKey, byte[]? rgbIV);
public override System.Security.Cryptography.ICryptoTransform CreateEncryptor (byte[] rgbKey, byte[] rgbIV);
override this.CreateEncryptor : byte[] * byte[] -> System.Security.Cryptography.ICryptoTransform
Public Overrides Function CreateEncryptor (rgbKey As Byte(), rgbIV As Byte()) As ICryptoTransform

Parameters

rgbKey
Byte[]

The secret key to use for the AES algorithm. The key size must be 128, 192, or 256 bits.

rgbIV
Byte[]

The initialization vector to use for the AES algorithm.

Returns

A symmetric AES encryptor object.

Exceptions

rgbKey is null.

rgbKey is not a valid size for this algorithm.

-or-

rgbIV size does not match the block size for this algorithm.

rgbKey is a known weak key for this algorithm and cannot be used.

-or-

rgbIV is null.

Remarks

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.

Applies to