Getting GnuPG::Interface working

Arthur Watts arthur.watts@gbst.com
Tue May 22 02:15:01 2001


Guys,

	Those of us who rely on GPG::PGP::MessageProcessor for automated
encryption / decryption in our Perl code have been forced to adopt Frank
Tobin's extensive OO rewrite of same, GnuPG::Interface. Whilst Mr Tobin has
undoubtedly put a lot of work into this module, I believe that the doco has
some 'rough edges', not the least of which is the example code for things
like encryption and decryption. If you copy and paste his example code
verbatim, it wont even compile, much less run. 

	If you copy and paste this slightly modified version of Mr Tobin's
example code, then ensure that you change the bolded sections and that you
have the appropriate encrypted file in the same directory as the code, it
should work (assuming that your GPG install is working at the command line
...)  :

============================================================================
=========================
use IO::Handle;
use IO::File;
use GnuPG::Interface;

my $passphrase = "some_passphrase";

my $gnupg = GnuPG::Interface->new();

$gnupg->options->hash_init( armor    => 0,                # non-ASCII
                              recipients => [ 'taur' ],                #
optional on decrypt, but it doesn't hurt ...
                              homedir => '~/.gnupg'                # default
location for most GPG installs
                            );

my ( $input, $output, $error, $passphrase_fh, $status_fh )
    = ( IO::Handle->new(),
        IO::Handle->new(),
        IO::Handle->new(),
        IO::Handle->new(),
        IO::Handle->new(),
      );

my $handles = GnuPG::Handles->new( stdin      => $input,
				     stdout     => $output,
				     stderr     => $error,
				     passphrase => $passphrase_fh,
				     status     => $status_fh,
				   );

my $cipher_file = IO::File->new( 'encrypted.gpg' );             # change to
refer to the name of your encrypted file
 
my $pid = $gnupg->decrypt( handles => $handles );

print $passphrase_fh $passphrase;
close $passphrase_fh;

while (<$cipher_file>) {
     print $input $_;
}

close $input;
close $cipher_file;

my @plaintext    = <$output>;   
my @error_output = <$error>;   
my @status_info  = <$status_fh>; 

print "STATUS: @status_info \n";
print "ERRORS: @error_output \n";
print "DECRYPTED TEXT : @plaintext \n";

  # clean up...
close $output;
close $error;
close $status_fh;


waitpid $pid, 0;  
============================================================================
=========================

	If I can just get the problems re decrypting large files (encryption
works fine using the author's suggested hack), this will be complete.

Enjoy,

Arthur