I experienced the following rather unhelpful exception at work today.
Padding is invalid and cannot be removed
With a stacktrace something along the following:
System.Security.Cryptography.RijndaelManagedTransform.DecryptData(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount, Byte[]& outputBuffer, Int32 outputOffset, PaddingMode paddingMode, Boolean fLast) +7596702
System.Security.Cryptography.RijndaelManagedTransform.TransformFinalBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount) +208
System.Security.Cryptography.CryptoStream.FlushFinalBlock() +33
System.Web.Configuration.MachineKeySection.EncryptOrDecryptData(Boolean fEncrypt, Byte[] buf, Byte[] modifier, Int32 start, Int32 length, IVType ivType, Boolean useValidationSymAlgo) +225
System.Web.Security.FormsAuthentication.Decrypt(String encryptedTicket) +246
After doing some searching and more or less complex debugging, and resetting the application pool and what not, I find the simple solution.
I had two projects running on my localhost which both used the default cookie name for forms authentication, which then apparently conflicted with each other. Do’h.
But well, problem solved.