我正在尝试使用RijndaelManaged
加密字符串,以便将其发送到第三方服务。 我已经在较旧版本的.Net框架(4.5、4.6.x)中实现了以下过程:
RijndaelManaged rm= new RijndaelManaged();
rm.KeySize = 256;
rm.BlockSize = 256;//causes exception in dotnet core 2.1
rm.Padding = PaddingMode.PKCS7;
rm.Key = Convert.FromBase64String(this.Key);
rm.IV = Convert.FromBase64String(this.IV);
var encrypt = rm.CreateEncryptor(rm.Key, rm.IV);
根据文档,RijndaelManaged
类可与BlockSize = 256
一起使用。但是,在代码运行在dotenet core 2.1中时,会抛出异常:
System.PlatformNotSupportedException: BlockSize must be 128 in this implementation. at System.Security.Cryptography.RijndaelManaged.set_BlockSize(Int32 value)
更新
感谢@Access-Denied的回答,根据此处,我注意到在 dotnet core 文档中可能有错误,我不能使用 256 个字符长度的BlockSize
与RijndaelManaged
类一起使用。正如我提到的,加密数据将被发送到第三方服务。我必须使用具有 32 个字符长度的 IV
的 Rijndael。我该怎么办?
aes
来保存它? 如果这不是有意的混淆,那么你可能很困惑。 - President James K. Polk