Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在CreateDecryptor方法中设置IV/Key时,为什么要在AESSManaged中设置它们呢?_C#_Cryptography_Aes_Cbc Mode - Fatal编程技术网

C# 在CreateDecryptor方法中设置IV/Key时,为什么要在AESSManaged中设置它们呢?

C# 在CreateDecryptor方法中设置IV/Key时,为什么要在AESSManaged中设置它们呢?,c#,cryptography,aes,cbc-mode,C#,Cryptography,Aes,Cbc Mode,在AES托管类中,有和属性。在示例中,设置这些属性,然后将其传递给CreateDecryptor方法。但是,在我的测试中,即使不设置IV/Key方法,也可以成功解密密文: 使用系统; 使用System.Security.Cryptography; 使用系统文本; 使用System.IO; 课堂测试 { //从https://stackoverflow.com/a/311179/569976 公共静态字节[]StringToByteArray(字符串十六进制) { int numbercars=十

在AES托管类中,有和属性。在示例中,设置这些属性,然后将其传递给
CreateDecryptor
方法。但是,在我的测试中,即使不设置IV/Key方法,也可以成功解密密文:

使用系统;
使用System.Security.Cryptography;
使用系统文本;
使用System.IO;
课堂测试
{
//从https://stackoverflow.com/a/311179/569976
公共静态字节[]StringToByteArray(字符串十六进制)
{
int numbercars=十六进制长度;
字节[]字节=新字节[numbercars/2];
对于(int i=0;i
那么,为什么要用属性来设置它们呢


我想您仍然需要通过属性设置模式(CBC、ECB、CTR等),但通过属性设置IV/键对我来说似乎是多余和不必要的?

这是多余和不必要的。它可能支持不同的使用和软件设计范例。你可能应该选择其中一种方式。我个人认为在Create方法中设置key和iv是最安全的。srDecrypt已经包含了iv。请按照代码倒转:csdecrypt:decrypt:decryptor:key,iv。