为什么 AesManaged.FeedbackSizeValue = 8 当 AesManaged.FeedbackSize = 128
Why AesManaged.FeedbackSizeValue = 8 when AesManaged.FeedbackSize = 128
我希望明确设置加密参数(从 .NET 4.7 默认值读取),以避免在未来的框架版本实现不同的默认值时出现解密困难。
为什么手动设置反馈FeedbackSize后,FeedbackSizeValue没有变化?
AesManaged aes = new AesManaged();
aes.Mode = CipherMode.CBC;
aes.KeySize = 256;
aes.Padding = PaddingMode.PKCS7;
aes.BlockSize = 128;
aes.FeedbackSize = aes.BlockSize;
这里是aes对象,看FeedbackSizeValue 8
- aes {System.Security.Cryptography.AesManaged} System.Security.Cryptography.AesManaged
- aes {System.Security.Cryptography.AesManaged} System.Security.Cryptography.AesManaged
BlockSize 128 int
BlockSizeValue 128 int
FeedbackSize 128 int
FeedbackSizeValue 8 int
+ IV {byte[16]} byte[]
IVValue null byte[]
+ Key {byte[32]} byte[]
KeySize 256 int
KeySizeValue 256 int
KeyValue null byte[]
+ LegalBlockSizes {System.Security.Cryptography.KeySizes[1]} System.Security.Cryptography.KeySizes[]
+ LegalBlockSizesValue {System.Security.Cryptography.KeySizes[1]} System.Security.Cryptography.KeySizes[]
+ LegalKeySizes {System.Security.Cryptography.KeySizes[1]} System.Security.Cryptography.KeySizes[]
+ LegalKeySizesValue {System.Security.Cryptography.KeySizes[1]} System.Security.Cryptography.KeySizes[]
Mode CBC System.Security.Cryptography.CipherMode
ModeValue CBC System.Security.Cryptography.CipherMode
Padding PKCS7 System.Security.Cryptography.PaddingMode
PaddingValue PKCS7 System.Security.Cryptography.PaddingMode
+ m_rijndael {System.Security.Cryptography.RijndaelManaged} System.Security.Cryptography.RijndaelManaged
+ Static members
CBC 模式没有反馈大小。见 CBC mode:
图片来自维基百科
也不需要指定块大小(aes.BlockSize = 128;
),AES只有一种块大小。 Rijndael 确实支持多种块大小,并且必须指定 128 位的块大小才能本质上成为 AES。虽然许多 Rijndael 实现默认为 128 位的块大小,但最好完全指定参数。
我希望明确设置加密参数(从 .NET 4.7 默认值读取),以避免在未来的框架版本实现不同的默认值时出现解密困难。
为什么手动设置反馈FeedbackSize后,FeedbackSizeValue没有变化?
AesManaged aes = new AesManaged();
aes.Mode = CipherMode.CBC;
aes.KeySize = 256;
aes.Padding = PaddingMode.PKCS7;
aes.BlockSize = 128;
aes.FeedbackSize = aes.BlockSize;
这里是aes对象,看FeedbackSizeValue 8
- aes {System.Security.Cryptography.AesManaged} System.Security.Cryptography.AesManaged
- aes {System.Security.Cryptography.AesManaged} System.Security.Cryptography.AesManaged
BlockSize 128 int
BlockSizeValue 128 int
FeedbackSize 128 int
FeedbackSizeValue 8 int
+ IV {byte[16]} byte[]
IVValue null byte[]
+ Key {byte[32]} byte[]
KeySize 256 int
KeySizeValue 256 int
KeyValue null byte[]
+ LegalBlockSizes {System.Security.Cryptography.KeySizes[1]} System.Security.Cryptography.KeySizes[]
+ LegalBlockSizesValue {System.Security.Cryptography.KeySizes[1]} System.Security.Cryptography.KeySizes[]
+ LegalKeySizes {System.Security.Cryptography.KeySizes[1]} System.Security.Cryptography.KeySizes[]
+ LegalKeySizesValue {System.Security.Cryptography.KeySizes[1]} System.Security.Cryptography.KeySizes[]
Mode CBC System.Security.Cryptography.CipherMode
ModeValue CBC System.Security.Cryptography.CipherMode
Padding PKCS7 System.Security.Cryptography.PaddingMode
PaddingValue PKCS7 System.Security.Cryptography.PaddingMode
+ m_rijndael {System.Security.Cryptography.RijndaelManaged} System.Security.Cryptography.RijndaelManaged
+ Static members
CBC 模式没有反馈大小。见 CBC mode:
也不需要指定块大小(aes.BlockSize = 128;
),AES只有一种块大小。 Rijndael 确实支持多种块大小,并且必须指定 128 位的块大小才能本质上成为 AES。虽然许多 Rijndael 实现默认为 128 位的块大小,但最好完全指定参数。