CFLib.org – Common Function Library Project

URLEncrypt(cQueryString, nKey)

Last updated February 19, 2003

Version: 2 | Requires: ColdFusion 5 | Library: SecurityLib

 
Rated 1 time(s). Average Rating: 5.0

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:

view plain print about
<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:

view plain print about
<cfscript>
/**
 * 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;
}
</cfscript>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Tayo Akinmade Tayo Akinmade added
arrayTrim
10 day(s) ago

Will Belden Will Belden added
longTime
15 day(s) ago

James Sleeman James Sleeman added
quickSort
25 day(s) ago

Ben Forta Ben Forta added
GetHostAddress
28 day(s) ago

Top Rated

Darwan Leonardo Sitepu EksporSQLData
Rated 5.0, 16 time(s)

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 13 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson