Here is what I am doing thus far, I appologize if I am long winded.
#### creating private/public key files, seems to work fine
use Crypt::OpenPGP; $pgp = Crypt::OpenPGP->new (); %attrib = ( 'Type' => 'RSA', 'Size' => '1024', 'Identity' => 'Garett L Holmes gaholmes@hotmail.com', 'Passphrase' => 'password', 'Cipher' => 'DES3', 'Verbosity' => '1', 'Compat' => 'PGP5', ); ($pubkey, $privkey) = $pgp->keygen( %attrib ) or die $pgp->errstr; $public = $pubkey->save; open(PUBLIC,">test.public") or die "COULD NOT OPEN pub\n"; print PUBLIC $public; close(PUBLIC); $private = $privkey->save; open(PRIVATE,">test.private") or die "COULD NOT OPEN priv\n"; print PRIVATE $private; close(PRIVATE);
#### Then I encrypt the data using the private key, seems to work
use Crypt::OpenPGP; use Crypt::OpenPGP::KeyRing; $pgp = Crypt::OpenPGP->new(PubRing => 'test.public'); $crypt = $pgp->encrypt( Compat => 'PGP5', Data => 'squeamish ossifrage', Recipients => 'gaholmes\@hotmail.com', Armour => 1, ); defined($crypt) ? print $crypt : die $pgp->errstr;
This is where I seem to lose it. I now want to decrypt $crypt using the secret key. I tried this this but know now that I am not understanding the passphrasecallback. I have read the documentation but can't seem to grasp it. After all the time I spent getting he modules installed and functioning on win32 I think I have brain burn. The module looks like just what I need and I would appreciate any assistance with understanding it. Thanks in advance.
boat73
$pgp = Crypt::OpenPGP->new ( "SecRing" => './pgp/test.private' )or die Crypt::OpenPGP->errstr; my $plaintext = $pgp->decrypt( "Data" => $crypt, "PassphraseCallback" => \&passphrase_cb ); die "decryption failed: ", $pgp->errstr unless $plaintext; print "PLAINTEXT IS $plaintext\n"; sub passphrase_cb { if (my $cert = $_[0]) { printf "Enter passphrase for secret key %s: ", $cert->key_id_hex; } else { print "Enter passphrase: "; } } &passphrase_cb(password); sub passphrase_cb { if (my $cert = $_[0]) { printf "Enter passphrase for secret key %s: ", $cert->key_id_hex; } else { print "Enter passphrase: "; } }

Edited by Chady -- fixed code tags.


In reply to Re: Re: Crypt::OpenPGP PassphraseCallback example please by boat73
in thread Crypt::OpenPGP PassphraseCallback example please by boat73

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.