It's possible, though seems unlikely, that you've got some strange characters in your opens (your posted code shouldn't suffer from that issue). 3-argument open will handle any escapes that that need handling. Swapping to Indirect Filehandles, that would be:
#!/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.8 (SunOS) mQGiBFDr..... -----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( my $in, "<", $datafile ) or die "Could not open csv file - $!"; my $plaintext = do{local $/;<$in>}; close $in; $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; open( my $out, ">", "$encrypted.pgp" ) or die "Could not open file for + encrypted data - $!"; print $out $ct; close $out;
Also note "\.[^.]*" doesn't mean what you likely thought, though it still works for your purposes for the given code.
Lastly, if you have your literal key pasted in the block for $ring, your use of qq delimiters might result in some weird interpolation, though that would likely have gotten caught by strict.
Hope some of this helps...
Update: Fixed typo, as per below.
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
In reply to Re: Code hanging with Crypt OpenPGP
by kennethk
in thread Code hanging with Crypt OpenPGP
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |