CFLib.org – Common Function Library Project

URLEncrypt(cQueryString, nKey)

Last updated February 19, 2003

author

Timothy Heald

Version: 2 | Requires: CF5 | Library: SecurityLib

Description:
This is actually two functions. The first urlEncrypt("name=value&name=value&name=value",key) you use when you would have a link or an action that you would be setting url variables in. The second urlDecrypt(key) you use on whatever page you are calling, or using as the form action page.

Return Values:
Returns an encrypted query string.

Example:

<CFSET Name = "Ray">
<CFSET Age = 28>
<CFSET Key = "MySecretBlah348123190">
<CFSET QS = "name=#Name#&age=#Age#">
<CFOUTPUT>
Link will be, foo.cfm#URLEncrypt(QS,key)#
</CFOUTPUT>

Parameters:

Name Description Required
cQueryString Query string to encrypt. Yes
nKey Key to use for encryption. Yes

Full UDF Source:

/**
 * Add security by encrypting and decrypting URL variables.
 * 
 * @param cQueryString      Query string to encrypt. (Required)
 * @param nKey      Key to use for encryption. (Required)
 * @return Returns an encrypted query string. 
 * @author Timothy Heald (theald@schoollink.net) 
 * @version 2, February 19, 2003 
 */
function urlEncrypt(queryString, key){
    // encode the string
    var uue = cfusion_encrypt(queryString, key);
        
    // make a checksum of the endoed string
    var checksum = left(hash(uue & key),2);
        
    // assemble the URL
    queryString = "/" & uue & checksum &"/index.htm";
        
    return queryString;
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson