PGP Command Line And Standard Input (stdin)
search cancel

PGP Command Line And Standard Input (stdin)

book

Article ID: 153179

calendar_today

Updated On:

Products

PGP Command Line

Issue/Introduction


This article describes scenarios in which you might encounter unexpected behavior from PGP Command Line when passing data to the Standard Input (stdin) of PGP Command Line. This pertains to PGP Command Line 8.5.0 running on Solaris, Linux, and Windows platforms.

Resolution


PGP Command Line is designed to receive/process data from a file or files. Therefore, passing output data from one application directly to PGP Command Line's stdin is unsupported behavior, and will cause unanticipated results. Similarly, passing input directly from the keyboard to PGP Command Line's stdin is also unsupported. Proper behavior is to write the data (which PGP Command Line must process) to a file or files, then pass the file(s) to PGP Command Line.

Examples

Suppose the output from one application is encrypted data, which must be decrypted by PGP Command Line before further processing of the data may continue. Below are some examples of how most users might attempt to accomplish this task with PGP Command Line. The first example shows improper use of PGP Command Line, while the second example depicts proper and supported use of PGP Command Line.

Improper
pgp --decrypt --passphrase passphrase --input - --output decrypted.txt 

While it seems like the above example might work, encrypted data is being passed directly to PGP Command Line's stdin stream--which is not supported. Proper behavior is to write the encrypted data to file first, then invoke PGP Command Line for decryption.

Proper
pgp --decrypt --passphrase passphrase --input - <encrypted.pgp 

OR

pgp --decrypt encrypted.pgp --passphrase passphrase 
Since the encrypted data was written to file first, the file can successfully be passed to PGP Command Line for decryption. As previously mentioned, passing data from the keyboard directly to PGP Command Line's stdin is also unsupported.

Improper
pgp --encrypt --recipient bob --input - --output encrypted.pgp 

Pressing enter at this point will simply create an empty file called encrypted.pgp. This occurs because PGP Command Line is expecting to receive input from a file or files, not from standard input.

Note: The above improper example might work in Windows because of the way Windows handles standard input. Regardless, PGP Command Line for Windows is not designed to operate in this way, so the above usage is still considered improper and unsupported in Windows.) An example of proper use is similar to the above examples. The data to be encrypted should be written to file first, then the file is passed to PGP Command Line for encryption.

Proper
pgp --encrypt --recipient bob --input - <encrypted.txt 

OR

pgp --encrypt --recipient bob encrypted.txt