解密错误 - >填充无效,数据大小不是块大小倍数 [英] Error in Decryption --> Invalid padding and Data size is not block size multiple

查看:90
本文介绍了解密错误 - >填充无效,数据大小不是块大小倍数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



你能帮我解决一下这个错误吗?任何人都在生产这个小问题。



i在进行解密时遇到问题,其中ingrainkey值低于2个错误。

1.解密错误 - >填充无效。

2.解密错误 - >数据大小不是块大小倍数。

为什么这两个上面的错误在使用当前密钥进行解密时得到但是同样的文件没有

任何错误我们无法下载这些文件形成了UI方面并且上面有两个错误,那些文件可以手动打开。

请在下载文件时帮助我从文件或描述/编码/代码方面出现问题。



提前寄宿。



问候,

Narasimha

解决方案

你并没有完全放弃丰富的信息。



因为你没有显示你创建的代码给你错误我建议你搜索一个工作示例并根据需要进行更改。

这里有CP文章可能对你有所帮助:简单加密和解密C#中的数据 [ ^ ]


HI全部,

请找到以下代码来解决这两个错误。





FileStream fSource;

FileStream fDestination;

ICryptoTransform dec;

Byte [] inputChar = null;

Byte [] decryptedChar = null;

// Int64 bfrSize = 9999999;

int count;

int decryptedCount;

int dataSize = 150000;



string sourcePath = ConfigurationSettings.AppSettings [EncryptedBackUpFilesPath] + fileName;

string destinationPath = ConfigurationSettings.AppSettings [DecryptedFiles] + fileName;

fSource = File.OpenRead(sourcePath);

fDestination = File.Create(de stinationPath);

inputChar = new Byte [dataSize + 16];

decryptedChar = new Byte [dataSize + 16];



dec = nKey.CreateDecryptor();



尝试

{

count = fSource .Read(inputChar,0,dataSize);

while(count> 0)

{

decryptedCount = dec.TransformBlock(inputChar,0,count,decryptedChar,0);

fDestination.Write(decryptedChar, 0,decryptedCount);

count = fSource.Read(inputChar,0,dataSize);

fDestination.Write(decryptedChar,0,decryptedCount);

AesManaged aes = new AesManaged();

// aes.Padding = PaddingMode.None;

}

decryptedChar = dec。 TransformFinalBlock(inputChar,0,count); //错误到达这里



fDestination.Write(decryptedChar,0,decryptedChar.Length);

Logger.LogError(destinationPath +被解密.POMID是 - >+ pomId);



// CryptoStream crStream = new CryptoStream(fDestination,nKey。 CreateEncryptor(),CryptoStr eamMode.Write);

//crStream.FlushFinalBlock();





}

catch(NAEException ex)

{

Logger.LogError(解密错误 - > + ex.Message);

}

终于

{

inputChar = null;

decryptedChar = null;

fSource.Flush();

fDestination.Flush();

fDestination.Close();

fSource.Close();

}



谢谢,

Narasimha

Hi All,

Could you please help me on this error anybody its very urgnet issue in production.

i have an issue while doing the decription with ingrainkey value got below 2 errors.
1. Error in Decryption --> Invalid padding.
2. Error in Decryption --> Data size is not block size multiple.
why these two above errors got while doing decription with current key but same files encripted without
any errors and we are not able to download the files form UI side and got above two errors those file manualy able to opened.
Please help me what is the issue here from files or decription/encription/ code side while download the files.

Thansks in advance.

Regards,
Narasimha

解决方案

You are not exactly giving away an abundance of information.

As you don't show the code you have created that gives you the error I recommend you to search for a working example and change it for your needs.
Here is CP article that might help you: Simple encrypting and decrypting data in C#[^]


HI All,
please find below code for those two errors.


FileStream fSource;
FileStream fDestination;
ICryptoTransform dec;
Byte[] inputChar = null;
Byte[] decryptedChar = null;
//Int64 bfrSize = 9999999;
int count;
int decryptedCount;
int dataSize = 150000;

string sourcePath = ConfigurationSettings.AppSettings["EncryptedBackUpFilesPath"] + fileName;
string destinationPath = ConfigurationSettings.AppSettings["DecryptedFiles"] + fileName;
fSource = File.OpenRead(sourcePath);
fDestination = File.Create(destinationPath);
inputChar = new Byte[dataSize + 16];
decryptedChar = new Byte[dataSize + 16];

dec = nKey.CreateDecryptor();

try
{
count = fSource.Read(inputChar, 0, dataSize);
while (count > 0)
{
decryptedCount = dec.TransformBlock(inputChar, 0, count, decryptedChar, 0);
fDestination.Write(decryptedChar, 0, decryptedCount);
count = fSource.Read(inputChar, 0, dataSize);
fDestination.Write(decryptedChar, 0, decryptedCount);
AesManaged aes = new AesManaged();
// aes.Padding = PaddingMode.None;
}
decryptedChar = dec.TransformFinalBlock(inputChar, 0, count);//Error getting here

fDestination.Write(decryptedChar, 0, decryptedChar.Length);
Logger.LogError(destinationPath + " is decrypted. POMID is --> " + pomId);

//CryptoStream crStream = new CryptoStream(fDestination, nKey.CreateEncryptor(), CryptoStreamMode.Write);
//crStream.FlushFinalBlock();


}
catch (NAEException ex)
{
Logger.LogError("Error in Decryption --> " + ex.Message);
}
finally
{
inputChar = null;
decryptedChar = null;
fSource.Flush();
fDestination.Flush();
fDestination.Close();
fSource.Close();
}

Thanks,
Narasimha


这篇关于解密错误 - >填充无效,数据大小不是块大小倍数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆