We have a requirement where we are encrypting Salesforce ID value using Crypto class method. Crypto.encryptWithManagedIV('AES128', key, data);
But it generates a key which contains +
sign and when we read this value in apex we get space for that +
sign.
We tried EncodingUtil.urlDecode
and EncodingUtil.urlEncode
. In that case +
sign is getting converted into %2B
and again we get space for that in the apex.
For Ex - Encoded value in URL:
gAbH0FIEK5l2m8wVKTV+p4R5QLay2D9jZ2BgsyQ3mJ1/9puMMIne6y5P6i3ZRidl
Encoded value in Apex:
gAbH0FIEK5l2m8wVKTV p4R5QLay2D9jZ2BgsyQ3mJ1/9puMMIne6y5P6i3ZRidl
Can someone please suggest how to handle the situation?
We can handle spaces by replacing it with +
sign. But I am not sure if it will throw an error for any specific characters/case.
%2b
does indeed convert back to+
. You've managed to somehow do it wrong (probably by not escaping the +, despite thinking you had).