Question

Exception: Source: mscorlib Message: Padding is invalid and cannot be removed.

Stack trace:

at System.Security.Cryptography.RijndaelManagedTransform.TransformFinalBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount) 
at System.Security.Cryptography.CryptoStream.FlushFinalBlock() 
at System.Web.Configuration.MachineKeySection.EncryptOrDecryptData(Boolean fEncrypt, Byte[] buf, Byte[] modifier, Int32 start, Int32 length, IVType ivType, Boolean useValidationSymAlgo) 
at System.Web.UI.Page.DecryptStringWithIV(String s, IVType ivType) 
at System.Web.Handlers.AssemblyResourceLoader.System.Web.IHttpHandler.ProcessRequest(HttpContext context) 
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() 
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Also our machine keys are not set to auto. So can someone please help. thanks

Was it helpful?

Solution

What is the source of the encrypted message? If you are sure the key and IV match, then you have to look at whether the block cipher mode (e.g. CBC, CTR, ECB) and the padding mode also match at the two ends of the process. If all these add up, then it's possibly you're truncating the byte array between encryption and decryption, possibly due to an off-by-one error.

Posting some of your code might help us diagnose.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top