Error - Padding is invalid and cannot be removed.

Topics: Cryptography Application Block
Sep 15, 2012 at 12:55 AM

Hi,

I am getting this error when I am using Cryptography block. This error is generated only with particular data. 

However when I pass the same data to another application using different Cryptography key, the data is decrypted correctly without any error.

This is the line where I get the error

plainText = Cryptographer.DecryptSymmetric("TestCrypto", encrypted);

Please let me know how I can fix this issue.

Thanks,

Sep 15, 2012 at 1:23 AM

Take a look at this FAQ: http://entlib.codeplex.com/wikipage?title=Why%20does%20the%20message,%20%22Padding%20is%20invalid%20and%20cannot%20be%20removed%22

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com 

Sep 15, 2012 at 1:31 AM

Thanks for your quick reply. However the link tells about when deploying the application on different machine. 

The issue that I have right now is on my development box. I have generated the key on my dev box and now testing my application on same box. Still getting the error. Do I need to generate new key?

Thanks

Sep 15, 2012 at 4:58 PM

Can you provide the specific details of your scenario in order to reproduce the the issue?  i.e. code, configuration, and specific steps, etc.

Thanks,

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com 

Sep 17, 2012 at 6:08 PM

Thanks Randy for your support in this. I got this working now. It was my error. I was trying to decrypt the data with different key (than the one which was used to encrypt) . 

Thanks