in reply to Re^4: Unable to get any decrypted output from $gpg->verify
in thread Unable to get any decrypted output from $gpg->verify

Here is an SSCCE showing an encryption/decryption round trip. Just set the three env vars accordingly and run.

#!/usr/bin/env perl use strict; use warnings; use feature 'say'; use Crypt::GPG; my $gpg = Crypt::GPG->new; $gpg->gpgbin ('/usr/bin/gpg'); $gpg->secretkey ($ENV{SECRET_KEY}); $gpg->passphrase ($ENV{GPG_PP}); $gpg->armor (1); my $plaintext = 'PerlMonks Rocks!'; say "Plain text: $plaintext"; my @enctext = $gpg->encrypt ([$plaintext], $ENV{TO_EMAIL}); say "Encrypted text: @enctext"; my $decrypted = $gpg->verify (\@enctext); say "Decrypted text: $decrypted";

🦛

Replies are listed 'Best First'.
Re^6: Unable to get any decrypted output from $gpg->verify
by xuo (Acolyte) on Aug 22, 2023 at 18:52 UTC
    Thank you. I'll try again this week-end.
    But here, my concern is : why should I add my secret key in plaintext ?

    Regards.

    Xuo.

      It's not the actual contents of the secret key, just the ID. $ENV{SECRET_KEY} is the 8 hex digits of your secret key ID. eg:

      $ export SECRET_KEY=0xDEADBEEF GPG_PP='Correct Horse Battery Staple' T +O_MAIL='foo@example.com'

      🦛

        Hi,
        Yes, this is what I've found on the Metacpan Crypt::GPG module description. But the script does not work at all. Then either I'm doing something wrong (bad secret key, bad passphrase, ... but running /bin/gpg -e ... works fine) or my perl module is not properly installed on my Mageia distribution.

        I've got other PCs but all using the same Mageia version. I'll try on my work PC but I'm not sure at all that the Crypt::GPG Perl module will be available. And it will tough to find an explanation to ask IT to install it :)

        Regards.

        Xuo.