function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Gautam_KasukhelaGautam_Kasukhela 

Encryption Decryption Issue

Hello All,
    I am facing a strange issue when decrypting a String that was encoded on the platform. Here is the scenario:-

I have a String named quoteId and I am encrypting the quoteId using AES256 alogorithm and key. Post the encryption, I am encoding it using Base64 encoding. The result is something like the below
Encrypted String:  jVWhnAUT6aoQFEOPmkJp/7QpE3V7uo2LjzC5VUWp31c=
Post encryption, I append the value to a URL query parameter, something like:
https"//xxxxxx?quoteId=jVWhnAUT6aoQFEOPmkJp/7QpE3V7uo2LjzC5VUWp31c=

Now when I decode and decrypt the value after reading the URL Params, it works fine and I am able to see the actual quoteId.

When I encrypt again another encrypted string is generated, something like: ZOWKWKWTSL8QIe7N8B3u80dC+hsmGFQIF0VjVGiB2II=

However, when the decode and decrypt the above, it does not work and I get a error saying "FATAL_ERROR System.SecurityException: last block incomplete in decryption".

What could be the issue? As the encryption, encoding , decoding and decryption logic is the same. Only observation that I have made is whenever there is a '+' in the generated encoded string, an exception is thrown. Is there anything that is probably throwing it off from the URL parameters?

Here is the code snippet
User-added image
AbhishekAbhishek (Salesforce Developers) 
If this post helps,

https://developer.salesforce.com/forums/?id=906F00000008ysEIAQ

Thanks.