http://www.perlmonks.org?node_id=1025619

ksublondie has asked for the wisdom of the Perl Monks concerning the following question:

I'm new to pgp and don't know where I'm going wrong. I have a script that transfers pgp files back & forth using ftp and encrypts and decrypts as needed using existing key files.

The current problem I have is signing while encrypting. I can encrypt just fine, but if I try to sign it during the encryption, I get the following error:

Could not find secret key with KeyID ....

Here's the code:

my $mysecring = Crypt::OpenPGP::KeyRing->new(Filename => $CONFIG{priva +tekey}) or handleError( "Error: ".Crypt::OpenPGP::KeyRing->errstr,1); my $mypubring = Crypt::OpenPGP::KeyRing->new(Filename => $CONFIG{publi +ckey}) or handleError( "Error: ".Crypt::OpenPGP::KeyRing->errstr,1); my $theirpubring = Crypt::OpenPGP::KeyRing->new(Filename => $CONFIG{ic +skey}) or handleError( "Error: ".Crypt::OpenPGP::KeyRing->errstr,1); my $pgp = Crypt::OpenPGP->new( SecRing=>$mysecring, PubRing=>$theirpubring, ) or handleError( "there was a problem creating constructor\n\n".C +rypt::OpenPGP->errstr,1); opendir(DIR, $CONFIG{ToDir}) or handleError( "Unable to open directory + $CONFIG{ToDir}: $!",1); my @directory = grep { !(/pgp/) && -f "$CONFIG{ToDir}/$_"} readdir(DIR +); closedir(DIR) or handleError( "Unable to close directory $CONFIG{ToDir +}: $!",1); print "found ".(scalar @directory)." items\n"; foreach (@directory){ print "encrypting $_\n"; my $encryption=$pgp->encrypt( Filename=>$CONFIG{ToDir}.'/'.$_, SignKeyID=>$keyid, SignPassphrase=>$pass, ) or handleError( "there was a problem encrypting the file\n\n +".$pgp->errstr); open FILE,'>'.$CONFIG{ToDir}.'/'.$_.'.pgp'; print FILE $encryption; close FILE; } }

Part (or rather most) of the problem is that I'm not sure what value I need to pass to SignKeyID: is it supposed to be a Crypt::OpenPGP::KeyBlock? a Crypt::OpenPGP::Signature? a string? I've tried setting it to $mysecring, a string of the file location, the secring's 8 char hex keyid, Fingerprint, userid, the 16 char hex subkeyid (all taken from the secring certificate details).

Delving into both the Crypt::OpenPGP documentation and code hasn't given me the answer...at least not one I can wrap my brain around.

Can someone enlighten me with what I'm doing wrong?

update: $mysecring and $mypubring make up the key pairs for my certificate -- $theirpubring is the public key for the party I'm sending the encrypted file to.