A System.Security.Cryptography.CryptographicException exception occurs when you try to use the RijndaelManaged class to decrypt data
Symptoms
When you try to use the RijndaelManaged class to decrypt data, a System.Security.Cryptography.CryptographicException exception may occur. Additionally, you may receive the following error message:
An unhandled exception of type ‘System.Security.Cryptography.CryptographicException’ occurred in mscorlib.dll
Additional information: PKCS7 padding is invalid and cannot be removed.
Resolution
This problem occurs because the initialization vector that you are using to try to decrypt the data is different from the initialization vector that you used to encrypt the data.
The RijndaelManaged class does not zero out an initialization vector. Therefore, each instance of the RijndaelManaged class has an initialization vector that is different from other instances of the RijndaelManaged class. Even if you use the same secret key, you cannot decrypt data that was encrypted by using a different initialization vector.
Note In rare cases, two instances of the RijndaelManaged class may have the same initialization vector.
