c# - AES256 CTR - 错误“指定的密钥不是此算法的有效大小”
问题描述
在我们的应用程序中,第三方工具用于加密文件,我们必须解密文件。我们负责提供密钥和 IV。但是我们无法将其解密并低于错误。
如果我使用openssl它工作正常,我能够成功解密文件
所有详细信息都附在这里,请帮助我缺少什么。
public string Decrypt(string cipherText, string key, string IV)
{
var rm = new RijndaelManaged();
rm.BlockSize = 256;
rm.KeySize = 256;
rm.Mode = CipherMode.ECB;
rm.Padding = PaddingMode.None;
var encryptedValue = Encoding.ASCII.GetBytes(cipherText);
var byteKey = ConvertStringToByte(key);
var byteIV = ConvertStringToByte(IV);
var DecryptorTransform = rm.CreateDecryptor(byteKey, byteIV); <-- **error is here**
示例键
密钥(64 个字符):d3dda598fc93a90d3de733fd3de733fdc1bb863de733fdc1bb86fbdc1bb86fb IV(32 个字符):d3dda598fc93a90d3de733fdc1bb86fb
错误详情
"message": "Specified key is not a valid size for this algorithm.", "details": "CryptographicException: Specified key is not a valid size for this algorithm.\r\nSTACK TRACE: at
System.Security.Cryptography.RijndaelManagedTransform.GenerateKeyExpansion(Byte[] rgbKey)\r\n 在 System.Security.Cryptography.RijndaelManagedTransform..ctor(Byte[] rgbKey, CipherMode 模式, Byte[] rgbIV, Int32 blockSize, Int32 feedbackSize, PaddingMode PaddingValue, RijndaelManagedTransformMode transformMode)\r\n 在 System.Security.Cryptography.RijndaelManaged.NewEncryptor(Byte[] rgbKey, CipherMode mode, Byte[] rgbIV, Int32 feedbackSize, RijndaelManagedTransformMode encryptMode)\r\n 在 System.Security.Cryptography .RijndaelManaged.CreateDecryptor(Byte[] rgbKey, Byte[] rgbIV)\r\n at Helix.Bdc.Services.AccessMaangement.SecretManager.Decrypt(String cipherText, String key, String IV)
解决方案
推荐阅读
- javascript - 具有最高数字的 Javascript 变量
- javascript - Firebase:在反应中从firestore读取数据
- visual-studio - 是什么导致 NuGet 将包还原到略有不同的文件夹结构?
- datetime - 日期字符串无法在 Google 表格中解析为日期/时间
- regex - 正则表达式特定匹配
- pandas - 具有 NaN 值的先前 n 元素的 Pandas 滚动总和
- mysql - 退款 MySQL 查询
- r - R中的绘图索引
- python - Pandas 将 html 表读取到数据框无法打印
- docker - 容器化应用程序 (Docker) 和 Jenkins Slave CICD