feng63600
feng63600

Reputation: 183

OpenPGP - en/decryption works in cmd but not in Perl script

The OpenPGP has been installed correctly and functions well. Below command works in Windows cmd:

gpg2 -r rept --encrypt myfile

However, while we are trying to automate above process using Perl system call:

system("gpg2 -r rept --encrypt myfile");

I got below error message: gpg: rept: skipped: No public key

Using gpg2 --list-keys, I indeed see the public key added. Could anyone provide with some insights of automating the OpenGPG processes?

Upvotes: 0

Views: 246

Answers (2)

mbethke
mbethke

Reputation: 935

Apart from the issue of system accounts that Jens Erat mentioned it might be useful to add an explicit absolute path to the desired gpg config via the --homedir parameter. Might be that the Windows version of gpg is a bit crippled in this respect and fails to find the keys if started from a different directory.

Depending on what you want to do with the encrypted data you could also have a look at some modules: I've had good experiences with Crypt::OpenPGP (although being pure Perl it's quite slow), and Crypt::PGPSimple looks like it would do what you want using an external gpg executable.

Upvotes: 1

Steffen Ullrich
Steffen Ullrich

Reputation: 123423

Given only few information in the question I can only guess and my guess is that rept contains a @ which gets interpreted because you have double quotes.

Apart from that please use strict; use warnings; so that you will find such errors early. Also use the multi-argument version of system so that no shell is involved, i.e. system("gpg2","-r",....). Otherwise you might risk code execution if the rept or myfile is determined by user input.

Upvotes: 3

Related Questions