Using GPG to encrypt raw data from a Perl Script

Ton Sistos antonio@moonlight.com
Thu Feb 22 22:03:03 2001


I am trying to use the GPG backend as an encryption engine for data that I
am sending across the internet through a Perl program on a Win32 system.  I
am using the following code:

use IPC::Open2;
sub Encrypt($$)
{
    my $data = shift;
    my $passphrase = shift;
    my @result;

    $passphrase .= "\n" if $passphrase !~ /\n$/;   # add a LF if it is not
already there
    if (eval { $pid = open2(*README, *WRITEME, 'gpg --passphrase-fd
0 --symmetric'); }) {
        print WRITEME $passphrase;
        print WRITEME $data;
        close WRITEME;
        @result = <README>;
        close README;
    }
    return join("", @result);
}
print Encrypt("Some random data", "a password") . "\n";

Of course, this doesn't work; GPG never returns (although it did seem to get
the passphrase), and the read on <README> hangs forever.  Does anyone know
of a way to get GPG to read from my Perl script and write back to it?  I
know that I could use temporary files to store $data and/or @result, but I'd
like to do this without incurring a disk-access execution penalty.

Please cc me on any responses, as I am not subscribed to the mailing list.
Thank you!

Antonio (Ton) Sistos