Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Crypt OpenPGP Brain twister

by jeteve (Pilgrim)
on Jun 20, 2011 at 22:47 UTC ( [id://910640]=perlquestion: print w/replies, xml ) Need Help??

jeteve has asked for the wisdom of the Perl Monks concerning the following question:

Fellow Monks,

I'm playing with Crypt::OpenPGP and I think I'm starting to loose my sanity. No matter how hard I try, I always end up by having some error from the PARI lib when I decrypt.

Here's my test script (shamelessly taken from this site #522597):

#!/usr/bin/perl use strict; use warnings; # generate public/private Crypt::OpenPGP keys. # encrypt some data # decrypt some data use Crypt::OpenPGP; my $size = 1024; my $ident = 'Me <me@example.com>'; my $pass = 'my passphrase'; my $public_file = 'public.pgp'; my $private_file = 'private.pgp'; my $keychain = Crypt::OpenPGP->new; my ($public, $private) = $keychain->keygen ( Type => 'RSA', Size => $size, Identity => $ident, Passphrase => $pass, Verbosity => 1, ) or die $keychain->errstr( +); my $public_str = $public->save; my $private_str = $private->save; print "Public encrypting_key: ".$public->encrypting_key ."\n"; print "Private encrypting_key: ".$private->encrypting_key ."\n"; open( PUB, '>', $public_file ) or die $!; print PUB $public_str; close(PUB); open( PRIV, '>', $private_file ) or die $!; print PRIV $private_str; close(PRIV); my $pgp = Crypt::OpenPGP->new( PubRing => $public_file ); my $cyphertext = $pgp->encrypt ( Data => 'Encrypt This', Recipients => $ident, Armour => 1, ) || die $pgp->errstr(); print $cyphertext; $pgp = new Crypt::OpenPGP( SecRing => $private_file ); my $plaintext = $pgp->decrypt ( Data => $cyphertext, Passphrase => $pass, ) || die $pgp->errstr(); print "plaintext: $plaintext\n";

It invariably ends with:

PARI:   ***   unexpected character: 
                                   ^-

Note that I've got the latest version of Crypt::OpenPGP from github, and that all the unit test pass very happily.

I must be going something very wrong. Thanks in advance for your help.

Replies are listed 'Best First'.
Re: Crypt OpenPGP Brain twister
by Khen1950fx (Canon) on Jun 21, 2011 at 17:24 UTC
    print "plaintext: $plaintext\n"

    That seems to be the major stumbling block. I tried it, and it came back undef each time, "undef" meaning failure. So I put together this example from the docs.

    First, we need to create a plaintext data packet object and serialize that object. Next, deserialize the object.

    I used Crypt::OpenPGP::Plaintext.

    #!/usr/bin/perl use strict; use warnings; use Crypt::OpenPGP::Plaintext; use Data::Dumper::Concise; my $data = 'foo bar'; my $file = '/root/Desktop/foo.txt'; my $pt = Crypt::OpenPGP::Plaintext->new( Data => $data, Filename => $file, Mode => 'b', ); binmode STDOUT, ':encoding(utf8)'; print Dumper(my $serialized = $pt->save); print Dumper($serialized = $pt->data);
      Um, its the decrypt call that is failing
        jeteve or others: Did this ever get a resolution? I'm repeating the same error on the decode. What to do?
      I've been struggling with this error myself.
      Problem is the keys generated by ->keygen were crap.
      My solution was to get some keys generated the "proper" way, and that worked perfectly.
        How do we generate the key in "proper" way?
Re: Crypt OpenPGP Brain twister
by Anonymous Monk on Jun 21, 2011 at 01:13 UTC
    It invariably ends with:

    Which method call generates that error?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://910640]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-25 19:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found