Skip to main content
March 1, 2010
Question

Decrypt problem

  • March 1, 2010
  • 1 reply
  • 985 views

Hello!

I have problem decripting string if the string is long.

I use

<cfset session.algo = "DES">
<cfset session.key = GenerateSecretKey(session.algo)>
<cfset session.enco = "HEX">

I have tried and other but nothing works for me.

also i do the encrypt like this: #URLEncodedFormat(Encrypt(tmpnodeid,session.key,session.algo,session.enco))#

and i pass this value as url parameter, which btw sometimes is cut.

Then i decrypt it like this: #Decrypt(URLDecode(URL.name),session.key,session.algo,session.enco)#

Can anyone please help me?

Thank you in advance!

Kind regards!

    This topic has been closed for replies.

    1 reply

    March 1, 2010

    Plz try this below code ..its working for me

    <cfset session.algo = "DES">

    <cfset session.enco = "HEX">

    <cfset session.key  = GenerateSecretKey(session.algo)>

    <cfset str = "This is my secret string." >

    <cfset enc = URLEncodedFormat(Encrypt(str, session.key , session.algo, session.enco))>

    <cfset dec = Decrypt(URLDecode(enc), session.key , session.algo, session.enco)>

    <cfoutput>


    <pre>
    string=#str#
    encrypted=#enc#
    decrypted=#dec#

    </pre>
    </cfoutput>
    March 1, 2010

    Hi

    Thank you for your reply.

    I have tried that and it works, but when the string is too long, it doesnt works, and some times it also cuts the url string.

    I can't understand this random behaiviour.

    Also i tried very long string in a page where don't have anything else but this code, and some times it decrypt it some times it doesn't.

    I read somewhere this:

    The Encrypt and Decrypt functions do not work with double-byte character sets. If you pass a string containing double-byte characters to the Encrypt function, and later pass the encrypted value to the Decrypt function, the string is not properly decrypted.

    And that it is known issue in coldfusion. I still hope, there is a way to fix that.

    March 1, 2010

    There are usually limits on the length of a query string, which will be a setting on the webserver you are using.

    Also, any variables in the URL scope are already decoded.  So you do not need to call the function URLDecode().

    If the encoding and decoding are taking place in seperate applications, make sure you are using the same encoding for the URL scope (this can be set in the application cfc/cfm).