URL/Database Safe Encryption

I was working on an application today where I needed to encrypt a query string. Using the encrypt() function alone would not work because it can generate non-URL friendly characters. There are the undocumented functions cfusion_encrypt() and cfusion_decrypt() that do just what I needed, but I didn't want to rely on any undocumented features in this application, so I did a little research. Turns out one way to go about this is to use tobase64().

Here is an example:

<!--- url/database safe encryption --->
<cfset myStringToEncrypt = "Encrypt Me"/>
<cfset urlSafeEncryptedString = ToBase64(Encrypt(myStringToEncrypt,12345))/>

<!--- decrypt url/database safe encryption --->
<cfset myDecryptedString = Decrypt(ToString(ToBinary(urlSafeEncryptedString)),12345)/>

I'll be using this method for any database/url safe encryption I need to do in the future.

Comments
BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.