naChoZ has asked for the wisdom of the Perl Monks concerning the following question:
Could anyone help me figure out how to use this module? I don't have a good understanding of OO, FYI...(Yes, I have read the tutorial on it here, no I still don't get it.)
I put together this sample script to try and simply decrypt an encrypted file that I have already created:
#!/usr/bin/perl -w # A simple example use IO::Handle; use GnuPG::Interface; use IO::File; # settting up the situation my $gnupg = GnuPG::Interface->new(); $gnupg->options->hash_init( armor => 1, homedir => '/root' ); # Note you can set the recipients even if you aren't encrypting! $gnupg->options->push_recipients( 'ftobin@uiuc.edu' ); $gnupg->options->meta_interactive( 0 ); # This time we'll catch the standard error for our perusing # as well as passing in the passphrase manually # as well as the status information given by GnuPG 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, ); # this time we'll also demonstrate decrypting # a file written to disk # Make sure you "use IO::File" if you use this module! my $cipher_file = IO::File->new( 'encrypted.gpg' ); # this sets up the communication my $pid = $gnupg->decrypt( handles => $handles ); # This passes in the passphrase #print $passphrase_fh $passphrase; print $passphrase_fh ""; close $passphrase_fh; # this passes in the plaintext #print $input $_ while <$cipher_file>; print $input $_ while <>; # this closes the communication channel, # indicating we are done close $input; #close $cipher_file; print "$pid"; my @plaintext = <$output>; # reading the output my @error_output = <$error>; # reading the error my @status_info = <$status_fh>; # read the status info # clean up... close $output; close $error; close $status_fh; waitpid $pid, 1; # clean up the finished GnuPG process
I was just trying ./test.pl < etest.txt.asc and all it does is print out the pid. How do I get it to decrypt the file? Either to console or an output file would be fine.
~~edited: Thu May 29 21:20:36 2003 by jeffa - removed blockquotes, removed leading whitespace in code
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: GnuPG::Interface
by fglock (Vicar) on May 28, 2003 at 20:26 UTC | |
by naChoZ (Curate) on May 28, 2003 at 20:33 UTC |