How encrypt data/text stream instead of a file?
dshaw at jabberwocky.com
Thu Dec 18 16:52:44 CET 2008
On Dec 18, 2008, at 1:14 AM, don rhummy wrote:
> All the examples of using GnuPG are of giving it a local filename to
> encrypt or decrypt. How do I pass it data, either as a stream or
> byte by byte?
GnuPG is designed to be able to accept a stream or a file. To do a
stream instead of a file, just don't give a filename. GnuPG will then
read data from standard input.
So, for example:
my-pipeline-that-streams-data | gpg --encrypt | my-pipeline-that-
You can freely mix streams and files as well:
my-pipeline-that-streams-data | gpg -o output-file.gpg --encrypt
gpg -o - --encrypt myfile | my-pipeline-that-accepts-encrypted-data
Anyway, that's how you do it on the command line. If you want to do
it inside a program, it depends on what language you're using and how
that language deals with calling out to a command line. In general,
though, you want to write data to the head of the GPG pipe, and read
data from the tail of the GPG pipe. I do this frequently in C via the
usual pipe/fork/exec/dup2 method.
More information about the Gnupg-users