If I only scale to 1 instance of an Azure Web App my application runs fine.
When I scale to 2 or more instances my application throws exception:
System.Security.Cryptography.CryptographicException: Padding is invalid and cannot be removed
errors during decryption which appear to be coming from the the second and third instances. When I scale back down to 1 instance the errors go away.
My application draws initialization vectors and ciphertext from a database which means all instances are receiving the same inputs.
I've tried recommendations from related but different questions such as ensuring FlushFinalBlock and explicitly setting padding and block modes mentioned here and here. Yi-Lun Luo experienced an invalid padding error when moving from development to Azure-based production, however I'm not able to find any references to errors being thrown when moving from single to multiple instances.
Has anyone else experienced this problem? Any suggestions of things to try would be greatly appreciated.
Clarification
Anand edited the question by dropping the word "intermittent", which caused an inaccurate description of the problem. When the application is scaled to 2 or more instances, some requests succeed and some throw a cryptographic exception. The application is a rest service. If ten requests are made from a single test page at one time, all will succeed if 1 instance is running. If 2 instances are running roughly half will succeed and half will fail. The trend continues with 3 instances. This behavior makes it seem like the initial instance is running properly and additional instances are not.