2

Not sure if anyone encountered this issue. Basically, I am doing an encoding of user details and then via email, I am sending the encoded value (which I got form crypto.encryptWithManagedIV) to the user in the email body

Below is the code:

AESKey is the encrypted value which I got using apex crypto class.
    String TargetUrl = 'https://mysandbox.cs88.force.com/redirectpage';
            String hyperlink  = '<a href="'+TargetUrl+'?uniqueId='+AESKey+'">Link to Join</a>';
            mail.setHtmlBody(htmlbdy);

When the user clicks this link I use get parameter on my redirect VF page

String KeyValue= ApexPages.currentPage().getParameters().get('uniqueId');
System.debug('RequestKey:-'+KeyValue);

On the browser the URL looks like :

https://mysandbox.cs88.force.com/?uniqueId=E+f7X10FDW3ExD1+jgfcRdHD1Helxk+vk=

But after doing getParameters().get('uniqueId'), I get 
E f7X10FDW3ExD1+jgfcRdHD1Helxk vk=

Similarly, if the URL has & then it ignores completely the rest https://mysandbox.cs88.force.com/?uniqueId=E&YhgD+f7X10FDW3ExD1jgfcRdHD18lUpsjofIyWRVzCW

In this case, I get only E by doing get parameters The plus sign is getting replaced by space, which then makes my entire decoding login fails.

Can we get the exact parameters what we have in the URL without any modifications in salesforce ??

3
  • 2
    You need to URL Encode the AESKet when adding to the target url
    – Eric
    Jan 20 '18 at 21:50
  • @Eric: Thanks thats is really helpful. I did the urlencoding for my AESKey. I still have one question that is after doing the urlencode i didn do any url decode but in the getparameters I am getting desired result. Is it String KeyValue= ApexPages.currentPage().getParameters().get('uniqueId'); already decodes the same. We dont need to explicitly do it ??
    – Abhik Dey
    Jan 20 '18 at 22:28
  • 1
    @AbhikDey Yes, the parameter is decoded for you automatically. If you'd generated your URL in Apex Code, you would not necessarily have needed to explicitly encode it to begin with.
    – sfdcfox
    Jan 20 '18 at 22:42