首页 > 解决方案 > 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)

标签: c#

解决方案


推荐阅读