Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Code hanging with Crypt OpenPGP

by danaj (Friar)
on Nov 12, 2013 at 03:40 UTC ( #1062115=note: print w/replies, xml ) Need Help??


in reply to Code hanging with Crypt OpenPGP

I just tried this on a 5.18.0 install, with kennethk's fix for pulling in the whole file, and it worked for me (Ubuntu). It encrypted various test files, and gpg 1.4.11 was able to decrypt them to the original input.

While David is right that Alt::Crypt::RSA::BigInt fixes a bunch of issues on some machines, I don't believe it has any impact here. It's calling Crypt::Rijndael::encrypt via Crypt::OpenPGP::CFB::encrypt.

I thought it might be computation time, but a 7MB csv file encrypted in about 0.5 seconds (with the XS Crypt::Rijndael so the actual encryption was about 3% of the total time taken). The time consuming parts of that half second on my machine were crc24, CFB encrypt (the Perl wrapper around the block encrypt), and Zlib deflate.

My next thought was hanging waiting for Crypt::Random to get entropy from /dev/random, but it looks like it's reading 282 bytes from /dev/urandom, and the latter shouldn't block.

Without knowing more (e.g. is the O/S Linux, Windows, Solaris, Sunos 4.1, etc.? What version of Perl? What versions of Crypt::OpenPGP and friends?) I'm not sure.

Replies are listed 'Best First'.
Re^2: Code hanging with Crypt OpenPGP
by Anonymous Monk on Nov 12, 2013 at 15:42 UTC
    I am using Linux and I still can not have it working, it still hangs and it does not show any erros, what code are you using that works for you? Can you posted here?
    Thanks!

      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/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FGoiZ+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;
        Just a note on this particular problem: I've been trying to debug a hang with this code, and what I've discovered is that -some keys- will cause a hang, and others will not. Keys are exported from Kleopatra as .asc files, and are useable in GPG4Win, but not the pure perl implementation.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2022-01-21 23:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (59 votes). Check out past polls.

    Notices?