SymmetricAlgorithm.IV 属性

定义

获取或设置对称算法的初始化向量 (IV)。Gets or sets the initialization vector (IV) for the symmetric algorithm.

public:
 virtual property cli::array <System::Byte> ^ IV { cli::array <System::Byte> ^ get(); void set(cli::array <System::Byte> ^ value); };
public virtual byte[] IV { get; set; }
member this.IV : byte[] with get, set
Public Overridable Property IV As Byte()

属性值

Byte[]

初始化向量。The initialization vector.

异常

试图将初始化向量设置为 nullAn attempt was made to set the initialization vector to null.

试图将初始化向量设置为无效大小。An attempt was made to set the initialization vector to an invalid size.

注解

当你创建一个 SymmetricAlgorithm 类的新实例或手动调用 GenerateIV 方法时,IV 属性会自动设置为新的随机值。The IV property is automatically set to a new random value whenever you create a new instance of one of the SymmetricAlgorithm classes or when you manually call the GenerateIV method. IV 属性的大小必须等于 BlockSize 属性除以8。The size of the IV property must be the same as the BlockSize property divided by 8.

派生自 SymmetricAlgorithm 类的类使用称为加密块链接(CBC)的链接模式,这需要一个密钥和一个初始化向量来对数据执行加密转换。The classes that derive from the SymmetricAlgorithm class use a chaining mode called cipher block chaining (CBC), which requires a key and an initialization vector to perform cryptographic transformations on data. 若要对使用 SymmetricAlgorithm 类之一加密的数据进行解密,必须将 Key 属性和 IV 属性设置为用于加密的相同值。To decrypt data that was encrypted using one of the SymmetricAlgorithm classes, you must set the Key property and IV property to the same values that were used for encryption.

对于给定的密钥k,不使用初始化向量的简单块密码会将相同的纯文本输入块加密为相同的密码文本输出块。For a given secret key k, a simple block cipher that does not use an initialization vector will encrypt the same input block of plain text into the same output block of cipher text. 如果纯文本流中存在重复的块,则密码文本流中会有重复的块。If you have duplicate blocks within your plain text stream, you will have duplicate blocks within your cipher text stream. 如果未经授权的用户知道你的纯文本块的结构,他们可以使用该信息破译已知的密码文本块,并可能恢复你的密钥。If unauthorized users know anything about the structure of a block of your plain text, they can use that information to decipher the known cipher text block and possibly recover your key. 若要对付此问题,请将上一块中的信息混合到对下一个块进行加密的过程中。To combat this problem, information from the previous block is mixed into the process of encrypting the next block. 因此,两个相同的纯文本块的输出是不同的。Thus, the output of two identical plain text blocks is different. 由于此方法使用前面的块对下一个块进行加密,因此需要使用初始化向量来加密第一个数据块。Because this technique uses the previous block to encrypt the next block, an initialization vector is needed to encrypt the first block of data.

适用于

另请参阅