Skip to main content
Participating Frequently
February 22, 2016
Question

Encrypt Decrypt Problem

  • February 22, 2016
  • 3 replies
  • 747 views

I am suddenly getting an error in a script that has been working for years where I encrypt an html file so that is can't be accessed via a browser and then decrypt it for later reference

The encrypting scheme is very basic:

<cfset archivefile="<HTML><BODY>" & paynowbutton & invoiceheader & invoicebody & "</body></html>">

<cfset tempinvoice=encrypt(archivefile,session.key)><!---session.key is a 4 digit PIN number--->

<cffile    action = "write"  file = "#application.LocalRoot#\invoices\#brokerid#_invoice.html"  output = "#tempinvoice#">

THEN TO UNENCRYPT

<cffile action="read"    file = "#application.LocalRoot#\invoices\#form.brokerid2#_invoice.html"  variable="invoice">

<cfset invoice=decrypt(invoice,session.key)>

THEN THE ERROR WHICH HAS BEEN INCREASING IN FREQUENCY

An error occurred while trying to encrypt or decrypt your input string: The input and output encodings are not same


ANY IDEAS??

    This topic has been closed for replies.

    3 replies

    mtnhomesAuthor
    Participating Frequently
    February 24, 2016

    I appreciate the suggestions, and adding charset on both ends of the transaction is a sound idea.

    What I ended up doing though is recreating the documents as PDF wherever the decrypting failed, and will use this process going forward.

    Legend
    February 23, 2016

    My vote for the most likely cause is what Carl said: encoding.

    A second more remote guess might be malware modifying your .html file with spam links, corrupting your encrypted data. I ran into this a couple years back with an account I had on a shared hosting provider. They had malware adding spam to html files.

    Carl Von Stetten
    Legend
    February 22, 2016

    Did you upgrade to a newer ColdFusion version after some of the encrypted files were generated?

    mtnhomesAuthor
    Participating Frequently
    February 22, 2016

    Negative. In fact the code above fails immediately. As soon as is encrypted and saved as a file I can not decrypt it. I can however decrypt the encrypted content while it is still a variable (before storing as a file)

    Carl Von Stetten
    Legend
    February 23, 2016

    "Encodings" might be the important bit.  I'm not well-versed in the subject, but it might be reading and writing using different character sets.  Try adding the "charset" attribute to both CFFILE calls.