I have a REST service (C#/IIS) where a small amount of data is encrypted using:
var encryptedText = MachineKey.Encode(bytes, MachineKeyProtection.All)
The encrypted string is later posted (to a REST service) and decoded using:
MachineKey.Decode(encryptedText, MachineKeyProtection.All)
The MachineKey is autogenerated, as shown in the web.config:
<machineKey
decryption="AES"
decryptionKey="AutoGenerate"
validation="AES"
validationKey="AutoGenerate" />
After the system was upgraded from .Net 4.5.1 to 4.5.2, I can no longer decrypt a string that was encrypted before the upgrade; it gives an HttpException "Unable to validate data". (I can decrypt a string encrypted after the upgrade.)
So something changed between 4.5.1 and 4.5.2 to the algorithm making them incompatible. I haven't been able to find anything online about this specific issue. Does anyone have specific details on this issue and/or a work around to make it work?
If it matters, the project is targetting .Net 4.0, not 4.5 or 4.5.1 or 4.5.2.
(As an aside, it sounds like it is not recommended to use the MachineKey.Encode/Decode for anything other than short-term encryption, possible because of this sort of issue? Also, I know Encode/Decode are deprecated now, but I have an existing system and can't change it at this point.)
UPDATE
This is only a problem when the keys are AutoGenerate. If I give them explicit values, everything continues to work fine after the upgrade.