I'm using Crypto API to encrypt values of input parameters on the application URL. It happens that once in a while gives me an internal error saying that "Specified key is not a valid size for this algorithm.". 9 out of 10 times it works. Anyone has any idea why it's happening this?

I immediatelly thought "What are the lengths of the key and string?"

Assuming your key is always the same, it must refer to the string to be encrypted and the message is wrong. Is that possible?