Been trying to get a CGI to decrypt an encoded, armored string sent via a post. If the string is saved to the file (say) 'file.txt' then "gpg --decrypt file.txt" from the bash shell will successfully decrypt the file, once I use the passphase 'abc123!' for the passphrase to the secret key.
However, if I try to decode this in the CGI script itself using Crypt::OpenPGP, I cannot get it to work. I've modified the code until the cows come home and most of the time I get the same error message "Symkey decrypt failed: Invalid secret key ID". Here's the relevant code snippet:
use Crypt::OpenPGP;
use CGI;
my $pgp = Crypt::OpenPGP->new(Compat => 'GnuPG');
my $cur=CGI->new();
my $phrase=$cur->param('phrase');
my ($plaintext,$valid,$sig)=$pgp->decrypt(Data => $phrase, Passphrase
+=> "abc123!");
print "[message: $plaintext<br>valid: $valid<br>signature: $sig<br>err
+or: ".$pgp->errstr."]<br><br>\n";
The last print statement returns the following:
message:
valid:
signature:
error: Symkey decrypt failed: Invalid secret key ID
And yet, if I dump the contents of the variable $phrase to the file file.txt and do gpg --decrypt file.txt from bash with passphrase abc123! to unlock the secret key it will successfully decode.