Encrypting URL parameters in Coldfusion.

So on looking around the internet for a suitable solution to passing encrypted strings sensibly through URL variables. I found all the usual suspects from encrypting with base64 conversion to straight encrypting. These all had the issue of mangling the string when passed through a URL, either CFWheels would lowercase everything (hence wrecking Base64 encoding), or in the case of simply encoding and even using URLEncode several characters would get trashed completely.

I found that the best solution was to provide the Encrypt() function with it’s additional params: algorithm and encoding. See http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=functions_c-d_40.html#1103962 for details. I picked the Hex encoding for a sensible character set (on retrospect UUEncode would work as well if you take in account the extra characters that will need to be URL encoded). So my encode call looked as follows:

encrypt(toEncodeString, algorithmkey, "CFMX_COMPAT", "HEX")

And the Decode would go as follows:

decrypt(urlStringToDecode, algorithmkey, "CFMX_COMPAT", "HEX")

About Simeon Cheeseman

I enjoy a wide variety of computer and board games, have a BSc in Computer Science and have played percussion for 18 years.

Posted on August 14, 2012, in ColdFusion and tagged , , , . Bookmark the permalink. 1 Comment.

  1. That’s a pretty neat solution. Thanks!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: