2

I am trying to decrypt a CSV using Coldfusion. The CSV has been encrypted using gpg4win. I have created a scheduled task in CF Admin which checks a folder for the encrypted file and if found, decrypts it and stores the result in another folder as a CSV file (Which will then be imported into a DB).

This is an excerpt of the code:

<cfparam name="Variables.InputFolderName" default="inputfolder" />
<cfparam name="Variables.OutputFolderName" default="outputfolder" />
<cfparam name="gKeyPassphrase" default="sampletestkey" />
<cfparam name="gEncryptionKeyID" default="sampletestid" />
<cfset inputFilePath = ExpandPath("/resources/uploads/csv/#Variables.InputFolderName#") />
<cfset outputpath = ExpandPath("/resources/uploads/#Variables.OutputFolderName#") />
<cftry>
    <cfdirectory directory="#inputFilePath#" name="Variables.EncryptedCSVFiles" filter="*.gpg" action="list" >
    <cffile action="read" file="#inputFilePath#\#name#" variable="Variables.EncryptedCSVData" />
    <cfexecute name="C:\Program Files (x86)\GNU\GnuPG\gpg2" arguments="--passphrase=#gKeyPassphrase# --batch -o #inputFilePath# -d -r #gEncryptionKeyID# ouputfile=#outputpath#/test.csv" timeout="300"></cfexecute>
 <cfcatch type="any">
    <!--- I tried emailing a cfdump of the error to myself but it didn't work --->
 </cfcatch>
</cftry>

When I run the scheduler manually, the 'This scheduled task was completed successfully.' displays in CF Admin but the a decrypted file is not created and I don't get any error reporting email either.

Will be really grateful if anyone can help me out with this.

Thank you.

Community
  • 1
  • 1
raul prakash
  • 113
  • 1
  • 3
  • 10

1 Answers1

1

(Note: I am assuming you first verified the above file settings work successfully from the command line. If not, go back and do that first)

If that is your actual CF code, it contains a few syntax errors. There is no closing quote after the arguments attribute, and no opening quote after outputfile attribute (which is also misspelled). So the CF code should compile, but might not produce any output files. Try fixing the quotes and you should get some output, even if its just an error:

<cfexecute name="C:\Program Files (x86)\GNU\GnuPG\gpg2.exe" 
       arguments="--passphrase=#gKeyPassphrase# --batch -o #inputFilePath# -d -r #gEncryptionKeyID#" 
       outputfile="#outputpath#/test.csv" 
       timeout="300">
</cfexecute>

Also, while I am not familiar with gpg2, a quick search suggests the -o parameter is used for the output file. Yet in your CF code the path comes from a variable named #inputFilePath#, which seems a little odd. Assuming it is not just an unfortunate naming choice, you may want to check your file paths as well.

Leigh
  • 28,765
  • 10
  • 55
  • 103
  • Thanks @Leigh for correcting my code. I tried your suggestion. It works from command line but CF seems to hang and the browser keeps trying to load the page. I am using [AxCrypt](http://www.axantum.com/AxCrypt/Downloads.html) as an alternative. It uses AES and I faced no issues decrypting with CF. Using AxCrypt: ` ` – raul prakash Jul 30 '13 at 20:29
  • *RE: but CF seems to hang* Might be waiting for input? With some programs it is better to set the exe as an argument and use the `/c` flag . See [example here](http://stackoverflow.com/a/1002585/104223). If you have time, try it and let me know if there is any change. Anyway, glad you found an alternative. (Edit: You may want to post your final code as an "answer", so it is more visible). – Leigh Jul 30 '13 at 20:37