How To Automatically Decrypt PGP-Encrypted Files Upon Upload

Posted by John Carl Villanueva on Fri, Dec 19, 2014 @ 04:59 AM


Whenever PGP files uploaded to your server happen to contain data needed for business processes, you might want to have those files decrypted automatically. That way, they can then be forwarded to the applications waiting to process them. JSCAPE MFT Server has an easy way of doing that and it's what we're going to show you today.

What we'd like to do


Figure 1



How to do it


In a nutshell, this method consists of creating a trigger that: 

1. Listens to a file upload event,

2. Limits the succeeding action to files that end with "pgp" (the file extension of most PGP files), and

3. Executes a trigger action that decrypts the file that was uploaded.

Let's walk you through those steps now.


1. Create a trigger


Go to the Triggers module and click the Add button to create a new trigger.


Figure 2



2. Select the "File Upload" Trigger Event Type


Start by assigning a name to this trigger. Use something descriptive, like "Auto Decrypt PGP Files for Processing". 

After that, expand the Event type drop-down list and select File Upload

Click the Next button to proceed.


Figure 3



3. Enter a Trigger Condition that limits the trigger to PGP files


For this example, we would like the decryption action to be carried out only if the following conditions are met:

✔ The file upload was successful, and

✔ The uploaded file has a "pgp" extension, which would mean it is a PGP-encrypted file.

This can be expressed using this logical expression:


(Success = TRUE) AND (LocalPath ~ ".*\.pgp")


wherein LocalPath is one of the variables pertinent to this particular trigger (the event type determines what variables are generated) and the expression that follows the ~ is what we call a regular expression


Enter the logical expression into the Trigger Conditions box and then click Next.


Figure 4



4. Add the "PGP Decrypt File" Trigger Action


Click the Add button to add the decrypt trigger action to this trigger.


Figure 5



Select the PGP Decrypt File trigger action from the drop-down list and then click OK.


Figure 6



Because we want JSCAPE MFT Server to decrypt the file that was recently uploaded, we simply enter %LocalPath% into the File text box. %LocalPath% is a variable that holds the complete path of the file that was recently uploaded. 

You can then enter the destination path of the resulting decrypted file. For now, let's just leave that entry blank. This would tell the system to simply place the decrypted file in the same directory as the source file (the uploaded file).

Next, tick the Private Decryption Key checkbox and then select the decryption key from the drop-down list. If you don't know how to generate OpenPGP keys for your server, read the article "3 Ways To Generate OpenPGP Keys".

Notice that check box labeled Delete Source? If you leave that unchecked, JSCAPE MFT Server will simply retain the source file after creating a decrypted version. Check out Figure 8 to see what we mean. The right panel of AnyClient contains both the uploaded file (which is encrypted) and its decrypted version.

Click OK when done.


Figure 7



Figure 8 



5. Finalize the Trigger

Once you're through clicking all the OK buttons and are back at the main screen, don't forget to click the Apply button. That will finalize your trigger creation process. 




That's it. Every time someone uploads a file that was encrypted by one of your managed file transfer server's OpenPGP public keys, your server will be able to automatically decrypt it. 

Please note that your server's decryption key can only decrypt files encrypted by its corresponding public key.


You might also want to read...


3 Ways To Generate OpenPGP Keys 

You Know It’s Time To Implement Server To Server File Transfer When..

How To Automatically PGP-Encrypt A File Upon Upload Using Triggers


Recommended download


Want to try this out yourself? Download the free evaluation edition of JSCAPE MFT Server now.


Download Now  

  Be up to date on tips like this, follow us on Twitter! 


Topics: Managed File Transfer, Business Process Automation, OpenPGP, Tutorials, Secure File Transfer, Triggers, regular expressions