gpt4 book ai didi

c# - 得到错误 : "Specified block size is not valid for this algorithm" while initialize AesCryptoProvider

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

我正在尝试为 AES 加密使用更大的 block 大小:

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.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

我确实遗漏了一些明显的东西,有什么线索吗?

最佳答案

似乎 AES 只支持等于 128 的 block 大小。看来您可以通过将数据处理为多个 block 来解决这个问题。

source

关于c# - 得到错误 : "Specified block size is not valid for this algorithm" while initialize AesCryptoProvider,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9300340/

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