1
Answer

Error in Decryption --> Invalid padding. and Data size is no

Photo of P Narasimha

P Narasimha

10y
1.1k
1
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

Answers (1)

0
Photo of Shweta Lodha
NA 15.7k 879.6k 10y
P Narasimha,
Reason is your CryptoStream isn't flushing all it's data to the MemoryStream before it was being read, and closing the stream causes it to flush everything to the backing stream.

So, if your padding is invalid, close or call FlushFinalBlock on any CryptoStream performing encryption before you access the encrypted data. Flush isn't enough.