PGPDECRYPT Decrypt a PGP encrypted file |
Top Previous Next |
This script command decrypts a file that was previously encrypted using PGP encryption and populates the %pgpdecryptfile variable with the name of the output file name. To decrypt a file you must have already imported the private key that matches the public key that was used to encrypt the file. Keys are imported with the PGPIMPORT script command or by using the Import Key functionality in the Robo-FTP Configurator. This command may by used to decrypt a file encrypted using the PGPENCRYPT script command or any external PGP or GPG encryption application.
The /pw option specifying the passphrase is required unless you saved the passphrase for the key in the Configurator.
Important When you use the Configurator to create new PGP keys you may optionally choose to save the passphrase. If you choose this option, the password is saved in an encrypted format in the Windows registry along with Robo-FTP's other settings. Later, when you use these keys for encryption or decryption, the passphrase will not appear in the console window nor will it be written to any log file. If you choose not to save the passphrase (or if you use externally generated PGP keys) then you will probably need to specify the passphrase in clear-text in a script file. Therefore, saving the passphrase when you create the key is the most secure option.
In the following example, the private key for decryption is the only private key in Robo-FTP and the passphrase was saved when the key was generated or imported.
PGPDECRYPT "encrypted.txt.pgp" "decrypted.txt"
You can also write the decrypted file to a different folder as shown below.
PGPDECRYPT "encrypted.txt.pgp" "c:\new\decrypted.txt"
If you did not save the passphrase when generating or importing the key then you will need to provide it using the /pw option as shown below.
PGPDECRYPT "encrypted.txt.pgp" "decrypted.txt" /pw="my passphrase is very nice"
The original file name is often embedded within a PGP encrypted file. Robo-FTP allows an encrypted file to be decrypted and saved using its original name in the current working folder by using the following syntax (Note: the empty quotes are used to pass no name to the [ target file ] argument).
PGPDECRYPT "encrypted.txt.pgp" ""
When no name is specified in the [ target file ] argument, use the %pgpdecryptfile variable to perform subsequent operations on the resulting decrypted file. In the following example we decrypt the file using its original name and then rename it by adding the current timestamp to the original name. The encrypted source file is then deleted:
PGPDECRYPT "unknown.pgp" "" /pw="secret!!!" SET new_name = %datetime + "_" + %pgpdecryptfile RENAME %pgpdecryptfile new_name DELETE "unknown.pgp"
Hint: If Robo-FTP is unable to find the correct private key for decryption, ask the person who encrypted the file for the Key ID of the public key that they used for encryption. The Key ID must match the value shown on the Manage Keys window in the Configurator. Some PGP software only displays an 8 character Key ID so in those cases you'll compare with the last 8 digits of the value shown in the Configurator. For a more precise comparison you can right-click the grid row and choose "Show Key Fingerprint" from the pop-up context menu.
Note: When the TMPFILE command is active, the output [ target file ] created by this command will have a different name until the decryption process is successfully completed.
Validating a digital signature requires access to the public key that matches the private key that was used to create the signature. Robo-FTP can only validate signatures when a copy of the PGP public key has been imported on the PGP menu in the Configurator. The /signature=required option may be used to force the PGPDECRYPT command to fail if the digital signature cannot be validated.
PGPDECRYPT "encrypted.txt.pgp" "decrypted.txt" /signature=required
These are the possible result codes returned by the PGPDECRYPT command:
Related command(s): PGPENCRYPT, PGPIMPORT, PGPSIGN, UNZIP, TMPNAME See also: Robo-FTP and PGP Cryptography, Configure PGP Menu |