AesCng.CreateEncryptor 方法

定义

创建 AES 对称加密器对象。

重载

CreateEncryptor()

使用当前键和初始化向量 (IV) 创建对称 AES 加密器对象。

CreateEncryptor(Byte[], Byte[])

用指定的密钥和初始化向量 (IV) 创建对称 AES 加密器对象。

CreateEncryptor()

使用当前键和初始化向量 (IV) 创建对称 AES 加密器对象。

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

返回

对称 AES 加密器对象。

例外

.NET 6 及更高版本:选择 CFB128 模式并保留密钥。

注解

使用此方法加密消息,然后使用具有相同签名的 CreateDecryptor 重载来解密此方法的结果。

适用于

CreateEncryptor(Byte[], Byte[])

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

用指定的密钥和初始化向量 (IV) 创建对称 AES 加密器对象。

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

参数

rgbKey
Byte[]

用于 AES 算法的密钥。 密钥大小必须为 128、192 或 256 位。

rgbIV
Byte[]

用于 AES 算法的初始化向量。

返回

对称 AES 加密器对象。

例外

rgbKeynull

rgbKey 的大小对于此算法无效。

- 或 -

rgbIV 的大小与此算法的块大小不匹配。

rgbKey 是此算法的已知弱密钥,不能使用。

- 或 -

rgbIVnull

注解

使用此方法加密消息,然后使用具有相同签名的 CreateDecryptor 重载来解密此方法的结果。

注意

如果已使用现有持久化密钥创建 AesCng 对象,并且想要在加密消息时使用该密钥,则需要设置 IV 属性,然后改为调用无 CreateEncryptor() 参数重载;否则,使用此方法将创建参数 rgbKey 指定的临时密钥。

适用于