1

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.

1
  • 1
    We'll need to see some code. You're doing something wrong. Tushar's answer is correct, and I tested and verified that %2b does indeed convert back to +. You've managed to somehow do it wrong (probably by not escaping the +, despite thinking you had).
    – sfdcfox
    Commented Sep 12, 2017 at 13:45

1 Answer 1

1

Convert the string in URL encode

EncodingUtil.urlEncode('gAbH0FIEK5l2m8wVKTV+p4R5QLay2D9jZ2BgsyQ3mJ1/9puMMIne6y5P6i3ZRidl','UTF-8');

Which will replace it to

gAbH0FIEK5l2m8wVKTV%2Bp4R5QLay2D9jZ2BgsyQ3mJ1%2F9puMMIne6y5P6i3ZRidl

Now in class simple get it from apex using apexpages.currentpage().getparameters().get('parameter Name'); and use it you will get expected output.

enter image description here

3
  • Tahnks for your reply. But when we decode the value again using EncodingUtil.urlDecode and get the value through apexpages.currentpage().getparameters().get('parameter Name'); It returns space instead of + sign. Commented Sep 12, 2017 at 13:37
  • 1
    Hey Tushar! Thanks for your quick reply. It worked for me also. I was getting the error because I was decoding it. If we get parameters directly then it gives the correct value. Thank you so much!!!!!!! Commented Sep 12, 2017 at 14:07
  • @GhanshyamKumar if this solved your problem then you can accept this answer. Commented Sep 12, 2017 at 16:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .