Stack Overflow Users,
I have a server side JQuery Datatable and I am attempting to encrypt the record ID. I've used this method on basic data tables in a CFLOOP but I have not been able to do it in JavaScript.
Below is my current code.
{
"targets": 1,
"data": "LAST_NAME",
<cfset L = "'+ data+'"/>
<cfset l_id = Encrypt(L,myKey,'AES/CBC/PKCS5Padding','HEX') />
"render": function ( data, type, row, meta )
{return '<a href="candidate/?svr=#l_id#">'+ data+'</a>';},
},
When I decrypt the url, it displays + data+. When I change it to use the L vairble, then I get the correct ID number but it is not encrypted
{return '<a href="candidate/?svr=#L#">'+ data+'</a>';}
I know it has something to do with using CFSCRIPT yet I am unclear how to use this. Any help would be great.
Although, there are many methods for encrypting the url, I found in my case the best method was to intercept the EMPLOYEE_ID in the JSON request prior to the JavaScript hand off.
<cfset ED_ID = Encrypt(EMPLOYEE_ID,myKey,'AES/CBC/PKCS5Padding','HEX')/>
<cfset obj = {
"EMPLOYEE_ID" = variables.ED_ID,
As you can see from the above example, the Employee_ID is modified before passing it to the JSON response. The successfully encrypts the employee id and creates the more secure URL.
If you're trying to encrypt a JavaScript variable, from ColdFusion, that isn't possible. ColdFusion is a server side language. It can't access JavaScript code and/or variables and vice versa. Any encryption with ColdFusion must be done server side, before any data is sent to the client.
While you can use cfscript, and some even prefer it, technically you don't "have to". Looping though a query and encrypting values can be done with either CFML or cfscript.
TryCF.com Example
CFScript
// simulate query data
myKey = generateSecretKey("AES");
qry = queryNew("l_id,last_name"
, "integer,varchar"
, [ {l_id=1, last_name="Johnson"}
, {l_id=2, last_name="Carson"}
, {l_id=3, last_name="Jackson"}
]
);
// encrypt query values
for (row in qry) {
qry.l_id[qry.currentRow] = encrypt(row.l_id, myKey,"AES/CBC/PKCS5Padding", "HEX");
}
writeDump(var=qry, label="Query (After)");
CFML
<!--- simulate query data --->
<cfset myKey = generateSecretKey("AES")>
<cfset qry = queryNew("l_id,last_name"
,"integer,varchar",
[ {l_id=1, last_name="Johnson"}
, {l_id=2, last_name="Carson"}
, {l_id=3, last_name="Jackson"}
]
)>
<!-- encrypt query values --->
<cfloop query="qry">
<cfset qry.l_id[qry.currentRow] = encrypt(qry.l_id, myKey,"AES/CBC/PKCS5Padding", "HEX")>
</cfloop>
<cfdump var="#qry#" label="Query (After)">