Skip to main content
Participating Frequently
Feb 22, 2016 9:49 PM UTC
Question

Encrypt Decrypt Problem

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 is closed to new replies. Start a new post to keep the conversation going.

    5 replies

    mtnhomesAuthor
    Participating Frequently
    Feb 24, 2016 5:40 PM UTC

    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.

    Translate
    Legend
    Feb 23, 2016 8:10 PM UTC

    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.

    Translate
    Carl Von Stetten
    Legend
    Feb 22, 2016 10:47 PM UTC

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

    Translate
    mtnhomesAuthor
    Participating Frequently
    Feb 22, 2016 10:53 PM UTC

    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)

    Translate
    Carl Von Stetten
    Legend
    Feb 23, 2016 12:36 AM UTC

    "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.

    Translate