• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to decrypt a URL

Guest
Oct 16, 2012 Oct 16, 2012

Copy link to clipboard

Copied

I encrypted a url that i would like to pass to another page, but can't seem to get it to decrypt it. This is the first time i am using this technic, so i might not be doing it right. Just been reading alot of the examples on the web and can't get it to work for me.

== Encrypted ==

<h3>URLEncodedFormat Example</h3>

<cfscript>

  theKey=generateSecretKey("AES");

  encrypted=encrypt(#qEdit.PersonID#, theKey, "AES", "HEX");

</cfscript>

<cfoutput>

  <a href="##" onclick="MM_openBrWindow('test2.cfm?Picture=#encrypted#','','resizable=yes,width=500,height=500')">Test Encode</a>

</cfoutput>

The encryption works fine in the url, but now i'm not sure how to decrypt it on my other page.

Views

2.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 17, 2012 Oct 17, 2012

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 18, 2012 Oct 18, 2012

Copy link to clipboard

Copied

You'll need to either save "theKey" to a session variable or pass it along in the URL.

If session variable:

decrypted = decrypt(url.Picture,session.varName,algorithm,enc);

If URL param:

decrypted = decrypt(url.Picture,url.varName,algorithm,enc);

^_^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Oct 18, 2012 Oct 18, 2012

Copy link to clipboard

Copied

If you are doing this for security then "or pass it along in the URL" is terrible advice, please don't follow it. Sorry WolfShade.

Create the key onSessionStart() and store it in the session scope, then you can reuse it throughout the site as needed.

Jason

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 19, 2012 Oct 19, 2012

Copy link to clipboard

Copied

LATEST

I agree with 12Robots that you should never send your key by URL. That is equivalent to publishing it, and therefore defeats the whole purpose of the encryption. 

There are 2  choices. Store the key as a client variable or as a session variable. I prefer session, because it involves just memory. (It's difficult to guess what someone's thinking!)

As 12Robots has said, the usual place to define session variables is in onSessionStart. Here, ColdFusion sets one value in memory for the entire user session. However, I think the requirements of the original post are not that simple.

You will have to store the PersonID and encrypted string in session scope, as you will need these values for validation later. Also, the URL has a dynamic part, namely, Picture=#encrypted#. This tells me there may be 2 or more Picture values per session. If so, then these session variables should be defined on the page itself, for example

<cfscript>

  session.theKey=generateSecretKey("AES");

  session.personID=qEdit.PersonID;

  session.encrypted=encrypt(session.personID, session.theKey, "AES", "HEX");

</cfscript>

<cfoutput>

  <a href="##" onclick="MM_openBrWindow('test2.cfm?Picture=#session.encrypted#','','resizabl e=yes,width=500,height=500')">Test Encode</a>

</cfoutput>

This defines a new key each time the current page is opened. I would then expect the validation on test2.cfm to jog like this

<!--- Ignored URLEncodedFormat and URLDecode, to keep story simple.  --->

<cfif isDefined("URL.Picture") AND URL.Picture IS decrypt(session.encrypted, session.theKey, "AES", "Hex")>

success

<cfelse>

failure

</cfif>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation