出现错误:“指定的块大小对此算法无效”初始化 AesCryptoProvider 时
我尝试使用更大的块大小进行 AES 加密:
private static void EncryptFile(string inFile, RSACryptoServiceProvider rsaPublicKey)
{
using (AesCryptoServiceProvider aes = new AesCryptoServiceProvider())
{
// Create instance of AesManaged for
// symetric encryption of the data.
aes.KeySize = 256;
// Allocating 64K
aes.BlockSize = 8 * 1024 * 64;
}
}
并遇到以下异常:
System.Security.Cryptography.CryptographyException 未处理
消息=指定的块大小对此算法无效。
来源=mscorlib StackTrace: 在 System.Security.Cryptography.SymmetricAlgorithm.set_BlockSize(Int32 价值) 在 ConsoleApplication4.Program.EncryptFile(String inFile, RSACryptoServiceProvider rsaPublicKey) 中 C:\Projects\ConsoleApplication4\Program.cs:第 117 行
我肯定错过了一些明显的东西,有什么线索吗?
I am trying to use larger block size for the AES Encryption:
private static void EncryptFile(string inFile, RSACryptoServiceProvider rsaPublicKey)
{
using (AesCryptoServiceProvider aes = new AesCryptoServiceProvider())
{
// Create instance of AesManaged for
// symetric encryption of the data.
aes.KeySize = 256;
// Allocating 64K
aes.BlockSize = 8 * 1024 * 64;
}
}
and hitting the following exception:
System.Security.Cryptography.CryptographicException was unhandled
Message=Specified block size is not valid for this algorithm.
Source=mscorlib StackTrace:
at System.Security.Cryptography.SymmetricAlgorithm.set_BlockSize(Int32
value)
at ConsoleApplication4.Program.EncryptFile(String inFile, RSACryptoServiceProvider rsaPublicKey) in
C:\Projects\ConsoleApplication4\Program.cs:line 117
I sure am missing somehting ovbious, any clue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
AES 似乎仅支持等于 128 的块大小。看来您可以通过将数据处理为多个块来解决此问题。
来源
It appears that AES only supports block size equal to 128. It appears that you can get around this by processing your data as multiple blocks.
source
每种算法仅支持特定的块大小。
请参阅
SymmetricAlgorithm.LegalBlockSizes
。Only certain block sizes are supported by each algorithm.
See
SymmetricAlgorithm.LegalBlockSizes
.