Andy Jarrett // Code. Develop. Create.

Encrypt and cfZip Example

I've modified the ColdFusion 8 livedocs version of Encrypt() to include:
  1. uploading a file e.g. .CSV
  2. reading contents and encrypting
  3. Zip the new encrypted file
It could probably do with some refinement as I was just using it for some generic testing tonight. Hope it comes in useful.

Encrypt and Zip Example

<cfif IsDefined("Form.uplfile")> <cftry> <cffile action = "upload" fileField = "uplfile" destination = "#expandPath('.')#" nameConflict = "MakeUnique" result="uploadedFile"> <cffile action="read" file="#uploadedFile.serverDirectory#/#uploadedFile.SERVERFILE#" variable="inFile"> <cfset theKey=generateSecretKey(Form.myAlgorithm) /> <cfset encrypted=encrypt(inFile, theKey, Form.myAlgorithm,Form.myEncoding) /> <cfset encryptedCSVLoc = uploadedFile.serverDirectory &"/encoded_"& uploadedFile.SERVERFILE /> <cffile action="write" file="#encryptedCSVLoc#" output="#encrypted#" /> <cfzip file="#uploadedFile.serverDirectory#/#uploadedFile.SERVERFILENAME#.zip" source="#encryptedCSVLoc#" /> <cfoutput>

Encrypted details

The algorithm: #Form.myAlgorithm#

The key: #theKey# (- save this, it's uniquely generated per encryption')

Click the link to download the zip file with the encrypted file in it #uploadedFile.SERVERFILENAME#.zip


</cfoutput> <cfcatch type="any"> <cfdump var="#cfcatch#"> </cfcatch> </cftry></cfif>

Encrypt new file

<cfoutput>
Select the encoding
  • Base64: the Base64 algorithm, as specified by IETF RFC 2045.
  • Hex: the characters A-F0-9 represent the hexadecimal byte values.
  • UU: the UUEncode algorithm (default).
Select the algorithm
  • AES: the Advanced Encryption Standard specified by the National Institute of Standards and Technology (NIST) FIPS-197.
  • DES: the Data Encryption Standard algorithm defined by NIST FIPS-46-3.
  • DESEDE: the "Triple DES" algorithm defined by NIST FIPS-46-3.
Upload CSV file
</cfoutput>

I’m here, learning and working away. If you liked this content and want to keep me going, consider buying me a coffee. Your support keeps this site running and the coffee brewing! ☕️