Link to home
Start Free TrialLog in
Avatar of brandonpowell
brandonpowell

asked on

Encrypt/Decrypt Issues

I am trying to encrypt variables being sent by my application, and then decrypt them when they get to the page
that will process the variables. I get the variables encrypted just fine, but when I try to decrypt them I get this.

An error occurred while evaluating the expression:


 v = Decrypt(ve, key)



Error near line 7, column 7.
--------------------------------------------------------------------------------

The value to be decrypted is not valid


Here is what I am doing to get the variables encrypted, and how I am trying to decrypt them.

This is some of the code on my sendmail_join.cfm page. This page subscribes my site users to my newsletter list after they fill out a simple form. After joining my newsletter, I want to encrypt the variables and send them to my referral
manager home page so they can refer three of their friends to our ezine.

This is how I encrypted the values.

*************************************************************

<cfset key = "myKey">

<cfset v = "#from_email#" & "," & "#firstName#" & "," & "#lastName#">

<cfset ve = Encrypt(v, key)>

<cflocation url="../index.cfm?fuseaction=e.referral&ve=#ve#" addtoken="no">
***************************************************************

The user has the option of referring three of his/her friends to our eznie, and if
he/she does the form.fieldnames will be send to the send_referral.cfm page. ( The encrypted variables are sent
in a hidden field named "ve" with the value set to value="#ve#")

The encrypted variables are sent. I can output them onto the send_referral.cfm template, but when I try to
decrypt them so that I can use them to send the referrals I get the error.

Here is the code I have to decrypt the variables.

*******************************************************************


<cfset key = "myKey">

<cfset ve = #ve#>

<cfoutput>#ve#</cfoutput>

<cfset v = Decrypt(ve, key)>

<cfoutput>#v#</cfoutput>
********************************************************************


The <cfoutput>#ve#</cfoutput> will output the encrypted variables, but the
<cfset v = Decrypt(ve, key) always throws an error.

Can you help me figure this out?

Sincerely,
Brandon Powell
Avatar of shooksm
shooksm

When you pass encrypted strings through the URL, you need to make sure you URL Encode them.

So your CFSET looks like the following:

<cfset ve = URLEncodeFormat(Encrypt(v, key))>

then on your receiving page:

<cfset v = Decrypt(URLDecode(ve), key)>
u can only decrypt those values - which are encrypted using the same key

so try this

<cfset x = encrypt('anand','akp')>
<cfset y = decrypt(x,'akp')>

let me know

K'Rgds
Anand
ASKER CERTIFIED SOLUTION
Avatar of jyokum
jyokum
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
you can try the internal CFUSION_ENCRYPT and CFUSION_DECRYPT functions (if its still available with newer versions of CF)
Im not into CF for long time so this may not work in newer versions...

https://www.experts-exchange.com/questions/20077276/Encrypting-URL-information.html

Avatar of brandonpowell

ASKER

Thanks! Works like a charm!