Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GnuPG::Interface

Status
Not open for further replies.

AHinMaine

ISP
Nov 27, 2002
264
US
Could anyone help me with this?
I've got decryption working fine, but now I'm trying to get encryption working
and having trouble. Here's my encryption routine.
Code:
        # {{{ encrypt
        my $mpw_file = IO::File->new( &quot;<$mpw&quot; ) || 
            die &quot;\n\nUnable to open file file.  $!\n&quot;;
        my $gnupg = GnuPG::Interface->new();
        $gnupg->options->hash_init( armor   => 1, homedir => '/root/.gnupg' );
        $gnupg->options->push_recipients( 'root@example.com' );
        $gnupg->options->meta_interactive( 0 );
        #my @original_plaintext = <$mpw_file>;
        ##my $passphrase = &quot;Three Little Pigs&quot;;
        
        # We'll let the standard error of GnuPG pass through
        # to our own standard error, by not creating
        # a stderr-part of the $handles object.
        my ( $input, $output, $error, $status_fh ) = 
            ( 
                IO::Handle->new(),
                IO::Handle->new(),
                IO::Handle->new(),
                IO::Handle->new()
            );
        my $handles = GnuPG::Handles->new( 
            stdin   =>  $input,
            stdout  =>  $output,
            stderr  =>  $error,
            status  =>  $status_fh
        );
           
        # this sets up the communication
        # Note that the recipients were specified earlier
        # in the 'options' data member of the $gnupg object.
        my $pid = $gnupg->encrypt( handles => $handles );
        # this passes in the plaintext
        # print $input @original_plaintext;
        print $input $_ while <$mpw_file>;
        # this closes the communication channel,
        # indicating we are done
        close $input;
        close $mpw_file;
        my @ciphertext     = <$output>;     # reading the output
        my @status_info    = <$status_fh>;  # reading the status info
        my @error_output   = <$error>;      # reading the error
        print @ciphertext;
        print @status_info;
        print @error_output;
        waitpid $pid, 0;  # clean up the finished GnuPG process
        # }}}

I commented the @original_plaintext lines out to see if that would help, it
didn't. When I run it with -wT it says &quot;broken pipe&quot;. With just -w, the
program just sits indefinitely. I tried running the script with &quot; < filename&quot;
out of desperation just to see if it might be waiting for the input to come
from STDIN. Yields the same &quot;broken pipe&quot; error. (FYI, I must disclaim that I
don't understand OO very well at all.)
I did isolate the problem to the problem to this line:
print $input $_ while <$mpw_file>;
But I'm not sure how to fix it. Any help would be appreciated. Thanx!

--
Andy
 
Andy,

Strange to see decryption working fine, now moving onto encryption ....

What's the value of the $input variable you're writing to?

Paul

It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...
 
I guess I'm not sure what the value actually is. It's declared in this section:
Code:
        my ( $input, $output, $error, $status_fh ) = 
            ( 
                IO::Handle->new(),
                IO::Handle->new(),
                IO::Handle->new(),
                IO::Handle->new()
            );

But I don't actually understand much about that. I'm just trying to follow the docs really, but the example in the docs only tells you how to encrypt a string that you declare in the script, not how to read a file and encrypt it.


--
Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top