in reply to Decrypting a message with Crypt::OpenPGP

The enc. message lacks the needed newlines. There must be a line break after the ---BEGIN ... --- line and two after the version line. Then one every 65 characters until the --- END .. --- line which has to start with one.

Change the my $PGPEncryptedMessage line to:

my $PGPEncryptedMessage = <<'EOM'; -----BEGIN PGP MESSAGE----- Version: haneWIN JavascriptPG v2.0 hIwDAAAAAAAAAAABA/4oJfsBR88yts6eY22RJDwEFyhxi2KWIJx6BR8fufIDN4j3 H79sCTN3UHDYoCV5zluSyhdSmM8beF1+hQ7PvSsonDOXrGfovIb9/cItQQg1CrgI 63Xje85qWW3IUpebnt4UlPnXx1sxK46GtJIEckYppWbXubCunAdFhhCyiq4ZBqQn Z9EAojfFrI8zkVIC/gq7cMZsu1wgn7/lcUvFewUNWWrU8ykAiC5t=R2eG -----END PGP MESSAGE----- EOM
It's also better to use single quotes for such texts to avoid accidental expansion. Ok, ` $ @ & might not be valid anyway in PGP messages.

PS: my $arg; should be my %arg;. Just add

use strict; use warnings;
at the very start of you script.

Replies are listed 'Best First'.
Re^2: Decrypting a message with Crypt::OpenPGP
by willjones (Sexton) on Apr 24, 2008 at 04:57 UTC
    Great Thanks. I put in the changes you indicated and now I am getting a different error.
    It says... "Error: Can't find a secret key to decrypt message"
    The private.pgp and public.pgp files are binary and have something like G4... in them
    I think it is finding these files okay because if I change the $secring assignment line to look for private1.pgp which doesn't exist it fails saying it can't find that file on that line.
    Am I missing something?
    Any ideas about what is wrong now?

    Thanks
      I don't have experience with this particular module only with PGP/GPG in general, so I saw this error. I know however that there are different binary formats for RSA/DSA keys, and PGP/GPG keys are such. E.g. I had to convert an binary RSA key generated under Windows once to a different format to use it under Linux.

      Just try to import the binary key with GPG or the PGP freeware and then to export it again in ASCII format.

        Thanks for your help... I finally got this worked out. One thing I had forgotten was the Passphrase.
        my $message = $pgp->decrypt(Data => $PGPEncryptedMessage, Passphrase => "secret_passphrase") or die "Error: ".$pgp->errstr;

        The other thing was that I had accidentally encrypted the original message with the wrong keyID.

        I found the software here useful in generating some keys to encode/decode with. http://www.pgpi.org/products/pgp/versions/freeware/dos/2.6.3i/

        It allows you to specify your passphrase when you generate.
        hi everyone, has this been solved? i am facing the same problem and it is driving me nuts as well.. any help would be greatly appreciated.