Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

Error in Decryption --> Invalid padding and Data size is not block size multiple

$
0
0

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.

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); ---here getting the those two errors.

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


Thanks & Regards, Narasimha


Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>