gpt4 book ai didi

C# System.Security.Cryptography - 为什么指定 key 和 IV 两次?

转载 作者:行者123 更新时间:2023-11-30 14:06:29 25 4
gpt4 key购买 nike

大多数展示如何使用 System.Security.Cryptography 中的 AES 代码进行加密的示例如下所示:

using (Aes aes = Aes.Create())
{
aes.Key = Key;
aes.IV = IV;
ICryptoTransform encryptor = aes.CreateEncryptor(aes.Key, aes.IV);

是否需要两次指定 key 和 IV - 一次指定给 Aes 对象,一次指定给 CreateEncryptor() 函数?或者在这种情况下,因为我已经指定了 key 和 IV,我可以调用不带参数的 CreateEncryptor() 形式吗?

最佳答案

你不必。您可以使用 the CreateEncryptor() overload (不带参数),如果您使用属性指定值:

public virtual ICryptoTransform CreateEncryptor() {
return CreateEncryptor(Key, IV);
}

这是the doc说:

Creates a symmetric encryptor object with the current Key property and initialization vector (IV).

或者,如果您之后不使用 aes 对象来创建其他加密器/解密器,则可以省略设置属性并使用带参数的重载。

关于C# System.Security.Cryptography - 为什么指定 key 和 IV 两次?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47536168/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com