Padding is invalid and cannot be removed exception while decrypting

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<p style="font:inherit; vertical-align:baseline; list-style-type:none; color:#666666; font-family:Segoe UI,Helvetica,Garuda,Arial,sans-serif; line-height:21px
Hi,
<p style="font:inherit; vertical-align:baseline; list-style-type:none; color:#666666; font-family:Segoe UI,Helvetica,Garuda,Arial,sans-serif; line-height:21px
I am encrypting and decrypting a file using AES algorithm(128bit). But while decrypting i am getting the below error:
<p style="font:inherit; vertical-align:baseline; list-style-type:none; color:#666666; font-family:Segoe UI,Helvetica,Garuda,Arial,sans-serif; line-height:21px
<strong style="margin:0px; padding:0px; border:0px; font-size:14px; font:inherit; vertical-align:baseline System.Security.Cryptography.CryptographicException: Padding is invalid and cannot be removed. <br/>
<strong style="margin:0px; padding:0px; border:0px; font-size:14px; font:inherit; vertical-align:baseline at System.Security.Cryptography.CapiSymmetricAlgorithm.DepadBlock(Byte[] block, Int32 offset, Int32 count) <br/>
<strong style="margin:0px; padding:0px; border:0px; font-size:14px; font:inherit; vertical-align:baseline at System.Security.Cryptography.CapiSymmetricAlgorithm.TransformFinalBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount) <br/>
<strong style="margin:0px; padding:0px; border:0px; font-size:14px; font:inherit; vertical-align:baseline at System.Security.Cryptography.CryptoStream.FlushFinalBlock() <br/>
<strong style="margin:0px; padding:0px; border:0px; font-size:14px; font:inherit; vertical-align:baseline at System.Security.Cryptography.CryptoStream.Dispose(Boolean disposing) <br/>
<strong style="margin:0px; padding:0px; border:0px; font-size:14px; font:inherit; vertical-align:baseline at System.IO.Stream.Close() <br/>
<strong style="margin:0px; padding:0px; border:0px; font-size:14px; font:inherit; vertical-align:baseline at System.IO.Stream.Dispose()
<p style="font:inherit; vertical-align:baseline; list-style-type:none; color:#666666; font-family:Segoe UI,Helvetica,Garuda,Arial,sans-serif; line-height:21px
The padding i am using is PKCS7. The error is intermittent, so i am not able to find out why this is happening. I have gone through other forums related to this issue but couldnt find anything helpful for this case.
<p style="font:inherit; vertical-align:baseline; list-style-type:none; color:#666666; font-family:Segoe UI,Helvetica,Garuda,Arial,sans-serif; line-height:21px
Any help on this would be helpful.

View the full article
 
Back
Top