Here is the code I'm using, with minimal changes from the OP (no fixing two argument open, etc.).

I generated a new key using gpg 1.4.11: "gpg --gen-key" (default RSA/RSA, 2048-bit, no expire). Then export with "gpg --armor --export ........" with the public key identifier.

I also plugged in Bruce Schneier's PGP key and it happily encrypts things for me (though I can't decrypt them of course)

When I tried the key you posted, I got an error in $ring->read. I get the same error if I use a key generated with openssl (because it isn't a PGP key).

#!/usr/bin/perl use strict; use warnings; use File::Basename; use Crypt::OpenPGP; my $ring = Crypt::OpenPGP::KeyRing->new( Data => qq^-----BEGIN PGP PUBLIC KEY BLOCK----- Version: GnuPG v1.4.11 (GNU/Linux) mQENBFKCi0wBCADAEhnYIcTEqusZo0atDDEzidDVgr5WxGulhf92k5ziSXdcwPfn B4cG8tKuuUeSUpPWAe5zgKN4wwkI1fQvdET8bYFppAKQwnkDpHXUhvX+3lYCxf2m Nm/6mZcCZQEb/JdY2D7cTYMu20IX4uakthmVMOGpIFrwwfrKd5cMrD1UkOf7D80d aou17nJIM2PSO0tVkwiImpiDPxR9/zC01EIgMVxlU0Rqc+viBfaZQ61IDobY+Guf XXVa3uA6jwTRIVyFKtfj7DyrLq81LcUuyOFeFLAXu5nfdjUQ93oW/jo53+h51fuK 8RQ5mQ4ThKtsaEMvFfQ4hoqbiZhrWcwOaQ5rABEBAAG0J0RhbmEgSmFjb2JzZW4g KFRlc3Qga2V5KSA8ZGFuYUBhY20ub3JnPokBOAQTAQIAIgUCUoKLTAIbAwYLCQgH AwIGFQgCCQoLBBYCAwECHgECF4AACgkQswvVk2rxbey6xAf/ZioN0eaRcP3Bl/xS k/EbPRRExWveNvKRy6CaDVXTgL1PUJ9mtY5Pi+mHzJ7CqXK0FmtaipkrwKFKfekz AKK2K0A7wvzXi2pMncP1iw58lgF+nNT0GAabYsaiyIx/lkhZ+A+R9veSXqBaPSKR jozQKzdXfiUa+RhjgQuBXiR74NqhY6g/T0Ah2dMm+j1rw3Hk+9oCPNpOFDeBKTnw 8o4s1JlQVqhzVMdZQHaQo0dJLpkBqjBLHn0q46UJu13KwOIlAakj8uVGyGXLfWbu saub2kzCjU+MN/ZAkJIkUO3OqFB/s7l8viMf7rtG0pVdCBtItaiizquiv8BruyZK nlTOGLkBDQRSgotMAQgArFn8WDPUz9qXK58c5rZnNUXBLGF/1g69MKgRnZC2KV0+ e+/i0R2f7F6k7teaNy1sjZnagf9UP7PoyUcN1ROwvJ7Gw2qVoYZlJrs6+cWfwChE ui31UvcsBvY4ht+vs5TAJ81IKZOCryLS1hySLLA7YvyyyR2A9bI6rsjJ282Uct0q wLM31a8geW1C8pMC4ZQTzuLEdUlG9fzazo0FI3layFGoiZ+sMc6y5eBYz6Ozx8vv guvkBDqss7VmWOkPqvbWK9+5AwrFgAy680Fbib7ets+ZKqPlyaZYjGAxIJNMS7pZ 5sgy9ePgKSOuHYPQphuOTFyaxJu7lRfNC9WIiE22vQARAQABiQEfBBgBAgAJBQJS gotMAhsMAAoJELML1ZNq8W3sO0wH+wY/WkuQSIyAksyGABhBzyltga9WKV0SmpTT BbupBRLMYg+/GubDfLU/irM7O4K0hBj/8UtGYMnG1RiJ4Kk+rCyn/6CPwYPLI+Fd EJjVh1MPcwWPxXWFAX3v1uH8A5Xyi6uZDW14QfhMKJ77bDqzIpdmxwStfQgwWHv4 nseqiaaaXriAlMZagZLBARYTb80PWV0LR61EO3DzZlHYRDbq4QlvwPg3lLugTabK FtLrMQEGtTKwXZI8Or7LmcRELid2LyJOAGPS2YgpF0czyyB1Pym1K+mybmFO0Ikn 4Gg6UfkmL9WdC3xLHHWNJFYn9iMXFBlFOyPr8G1Kuq6bq05G3b4= =j1aQ -----END PGP PUBLIC KEY BLOCK-----^ ); my $datafile = "original.csv"; # Get just name of the original file to name the new encrypted file. my ( $encrypted ) = fileparse( $datafile, "\.[^.]*" ); # $name, $path, + $suffix open( INFILE, "< $datafile" ) or die "Could not open csv file - $!"; #my $plaintext = <INFILE>; my $plaintext = do{local $/;<INFILE>}; close INFILE; $ring->read; my $kb = $ring->find_keyblock_by_index(0); my $cert = $kb->encrypting_key; my $pgp = Crypt::OpenPGP->new( Compat => 'GnuPG' ); my $ct = $pgp->encrypt( Key => $cert, Data => $plaintext, Armour => 1 +) or die "ERROR: " . $pgp->errstr; warn "writing to $encrypted.pgp\n"; open( OUTFILE, "> $encrypted.pgp" ) or die "Could not open file for en +crypted data - $!"; print OUTFILE $ct; close OUTFILE;

In reply to Re^3: Code hanging with Crypt OpenPGP by danaj
in thread Code hanging with Crypt OpenPGP by Anonymous Monk

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.