Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2022-05-17 23:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (68 votes). Check out past polls.

    Notices?