I am using ColdFusion to encrypt and decrypt. I have variable active with a value 1. I want to create a URL containing the encrypted value of active like:
http://localhost:8500/blueline/ActivateRegistration.cfm?email=abc@gmail.com&active=!#
Here !# is the encrypted value of 1.
At the other end ie ActivateRegistration.cfm I need to decrypt active with same private key and find the original value. But I am not getting correct encrypted string when I try the following code:
<cfset activeValue = url.active>
The reason is the encrypted value also contains the special character # within the string. Can anyone help? Also how can I handle ColdFusion special characters/keywords?
The other guys have covered how to escape URL-meaningful characters that occur within a URL value, but there’s one last piece of the puzzle that stands clarification / correction.
You’re not having problems with the encrypted string because # is a special character to ColdFusion, it’s because it has special meaning in the URL itself. Within a URL, a # is the delimiter between the address of the document on the server, and the specific fragment being targeted within the document (ie: a bookmark / anchor tag). As this information is deemed not relevant to the server, the browser never sends it, so the server never gets it.
It’s similar to if you had a parameter value which in itself had an embedded ampersand (&): as far as URLs go, that’s a delimiter between parameters, not part of the parameter value, so CF would not see that as part of the value of a URL variable, it’d see it as the delimiter between two variables.
To avoid all this confusion, as the other respondents said, you need to always URL-encode values that need to go on a URL that contain characters that are meaningful to the URL-addressing schema itself.