Encrypt and cfZip Example
- uploading a file e.g. .CSV
- reading contents and encrypting
- Zip the new encrypted file
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> </cfoutput>