Click here to Skip to main content
15,907,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Comments
KaushalJB 3-Nov-14 7:35am    
I guess this files are XML and probably the code needs to be changed for Encryption/Decryption.

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#[^]
 
Share this answer
 
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900