How encrypt data/text stream instead of a file?

don rhummy donrhummy at
Thu Dec 18 18:49:41 CET 2008

OK, so I need to put the data into the out stream. Can you give some sample code from C doing this? I'm not 100% clear on the order, etc of calling gpg and sending the data to "out." Thanks!

--- On Thu, 12/18/08, David Shaw <dshaw at> wrote:

> From: David Shaw <dshaw at>
> Subject: Re: How encrypt data/text stream instead of a file?
> To: donrhummy at
> Cc: gnupg-users at
> Date: Thursday, December 18, 2008, 10:52 AM
> 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-accepts-encrypted-data
> You can freely mix streams and files as well:
>  my-pipeline-that-streams-data | gpg -o output-file.gpg
> --encrypt
> Or
>  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.
> David


More information about the Gnupg-users mailing list