GPG(3)
๐ GPG(3) โ the Crypt::GPG manual, but make it make sense ๐
okay bestie, sit down, hydrate, and let me tell you about Crypt::GPG โ an Object Oriented Interface to GnuPG. That's the whole NAME situation right there. No cap. ๐
โจ VERSION โจ
the receipts, literally:
$Revision: 1.64 $
$Date: 2007/04/02 13:34:25 $
๐ธ SYNOPSIS ๐ธ
here's the vibe, in code:
use Crypt::GPG;
my $gpg = new Crypt::GPG;
$gpg->gpgbin('/usr/bin/gpg'); # The GnuPG executable.
$gpg->secretkey('0x2B59D29E'); # Set ID of default secret key.
$gpg->passphrase('just testing'); # Set passphrase.
# Sign a message:
my $sign = $gpg->sign('testing again');
# Encrypt a message:
my @encrypted = $gpg->encrypt ('top secret', 'test@bar.com');
# Get message info:
my @recipients = $gpg->msginfo($encrypted);
# Decrypt a message.
my ($plaintext, $signature) = $gpg->verify($encrypted);
# Key generation:
$status = $gpg->keygen
('Test', 'test@foo.com', 'ELG-E', 2048, 0, 'test passphrase');
print while (<$status>); close $status;
# Key database manipulation:
$gpg->addkey($key, @ids);
@keys = $gpg->keydb(@ids);
# Key manipulation:
$key = $keys[0];
$gpg->delkey($key);
$gpg->disablekey($key);
$gpg->enablekey($key);
$gpg->keypass($key, $oldpassphrase, $newpassphrase);
$keystring = $gpg->export($key);
๐ฆ DESCRIPTION ๐ฆ
so basically: the Crypt::GPG module hands you the entire functionality of the GnuPG encryption tool (www.gnupg.org) through an object oriented interface. slay. ๐
It gives you methods for encryption, decryption, signing, signature verification, key generation, key certification, export and import. Key-server access is on the todo list (we'll get there, babe, manifesting it ๐ง).
real talk: this release of the module may create compatibility issues with previous versions. If you find any such problems, or any bugs or documentation errors, please do report them to crypt-gpg at neomailbox.com. the devs literally want the feedback, don't be shy. ๐ซถ
๐ CONSTRUCTOR ๐
new()
creates and returns a new Crypt::GPG object. that's it, that's the whole thing, iconic behavior. โจ
๐ DATA METHODS ๐
these are the setters, the little knobs you turn to make your object behave. each one sets an instance variable, iykyk.
gpgbin($path)โ sets theGPGBINinstance variable, which is the path to the GnuPG binary. yes bestie, tell it where the executable lives. ๐gpgopts($opts)โ sets theGPGOPTSinstance variable, which you can use to pass additional options to the GnuPG binary. For proper functioning of this module, it is advisable to always include'--lock-multiple'in the GPGOPTS string. do not skip this, I'm begging. ๐delay($seconds)โ sets theDELAYinstance variable. This is no longer necessary (nor used) in the current version of the module, but it remains so existing scripts don't break. legacy queen, we keep her around for the nostalgia. ๐secretkey($keyid)โ sets theSECRETKEYinstance variable, which may be a KeyID or a username. This is the ID of the default key to use for signing. ๐passphrase($passphrase)โ sets thePASSPHRASEinstance variable, required for signing and decryption. you literally cannot do either without it. ๐text($boolean)โ sets theTEXTinstance variable. If set true, GnuPG will use network-compatible line endings for proper cross-platform compatibility, and the plaintext will gain a newline at the end, if it does not already have one. ๐armor($boolean)โ sets theARMORinstance variable, controlling the ASCII armoring of output. The default is to use ascii-armoring. heads up: the module has not been tested with this option turned off, and most likely will not work if you switch this off. soโฆ don't. ๐detach($boolean)โ sets theDETACHinstance variable. If set true, thesignmethod will produce detached signature certificates, else it won't. The default is to produce detached signatures. โ๏ธencryptsafe($boolean)โ sets theENCRYPTSAFEinstance variable. If set true, encryption will fail if trying to encrypt to a key which is not trusted. This is the default. Turn this off if you want to encrypt to untrusted keys. your call, bestie, but the default is the default for a reason. ๐ก๏ธversion($versionstring)โ sets theVERSIONinstance variable, which you can use to change theVersion:string on the GnuPG output to whatever you like. ๐ท๏ธcomment($commentstring)โ sets theCOMMENTinstance variable, which you can use to change theComment:string on the GnuPG output to whatever you like. ๐ฌnofork($flag)โ sets theNOFORKinstance variable, which if set to a true value will causekeygen()not to fork a separate process for key generation. ๐ด๐ซdebug($boolean)โ sets theDEBUGinstance variable, which causes the raw output of Crypt::GPG's interaction with the GnuPG binary to be dumped toSTDOUT. By default, debugging is off. ๐
๐ฅ OBJECT METHODS ๐ฅ
the main character methods. the ones doing the actual work.
sign(@message)โ signs@messagewith the secret key specified withsecretkey()and returns the result as a string. โ๏ธdecrypt(\@message, [\@signature])โ this is just an alias forverify(). lowkey redundant, highkey convenient. ๐verify(\@message, [\@signature])โ decrypts and/or verifies the message in@message, optionally using the detached signature in@signature, and returns a list whose first element is plaintext message as a string. If the message was signed, aCrypt::GPG::Signatureobject is returned as the second element of the list. ๐ต๏ธโ๏ธ
The Crypt::GPG::Signature object can be queried with the following methods:
$sig->validity(); # 'GOOD', 'BAD', or 'UNKNOWN'
$sig->keyid(); # ID of signing key
$sig->time(); # Time the signature was made
$sig->trusted(); # Signature trust level
msginfo(@ciphertext)โ returns a list of the recipient key IDs that@ciphertextis encrypted to. ๐ฌencrypt($plaintext, $keylist, [-sign] )โ encrypts$plaintextwith the public keys of the recipients listed in$keylistand returns the result in a string, orundefif there was an error while processing. Returnsundefif any of the keys are not found. ๐
Either $plaintext or $keylist may be specified as either an arrayref or a simple scalar.
If $plaintext is an arrayref, it will be join()ed without newlines.
If you want to encrypt to multiple recipients, you must use the arrayref version of $keylist. A scalar $keylist works for only a single key ID.
If the -sign option is provided, the message will be signed before encryption. The secret key and passphrase must be set for signing to work. They can be set with the secretkey() and passphrase() methods.
addkey($key, $pretend, @keyids)โ adds the keys given in$keyto the user's key ring and returns a list ofCrypt::GPG::Keyobjects corresponding to the keys that were added.$keymay be a string or an array reference. โ
If $pretend is true, it pretends to add the key and creates the key object, but doesn't actually perform the key addition. fake it till you make it, but make it clear you're faking it. ๐ญ
Optionally, a list of key IDs may be specified. If a list of key IDs is specified, only keys that match those IDs will be imported. The rest will be ignored. ๐ โ๏ธ
export($key)โ exports the key specified by theCrypt::GPG::Keyobject$keyand returns the result as a string. ๐คkeygen($name, $email, $keytype, $keysize, $expire, $passphrase)โ creates a new keypair with the parameters specified. The only supported$keytypecurrently is'ELG-E'.$keysizecan be any of1024,2048,3072or4096. Returnsundefif there was an error, otherwise returns a filehandle that reports the progress of the key generation process similar to the way GnuPG does. The key generation is not complete till you read an EOF from the returned filehandle. do not walk away early, bestie, it's not done. ๐ถcertify($keyid, $local, @uids)โ certifies to the authenticity of UIDs of the key with ID$keyid. If$localis true, the certification will be non-exportable. The@uidsparameter should contain the list of UIDs to certify โ (the first UID of a key is 0). โkeydb(@keyids)โ returns an array ofCrypt::GPG::Keyobjects corresponding to the Key IDs listed in@keyids. This method used to be calledkeyinfoand that is still an alias to this method. old name, same energy. ๐๏ธparsekeys(@keylist)โ parses a raw GnuPG formatted key listing in@keylistand returns an array ofCrypt::GPG::Keyobjects. ๐งฉkeypass($key, $oldpass, $newpass)โ change the passphrase for a key. Returns true if the passphrase change succeeded, false if not, orundefif there was an error. ๐delkey($keyid)โ deletes the key specified by theCrypt::GPG::Keyobject$keyfrom the user's key ring. Returnsundefif there was an error, or1if the key was successfully deleted. ๐๏ธdisablekey($keyid)โ disables the key specified by theCrypt::GPG::Keyobject$key. ๐ซenablekey($keyid)โ enables the key specified by theCrypt::GPG::Keyobject$key. โ
๐ Crypt::GPG::Signature ๐
Documentation coming soon. we're all waiting, bestie. โณ
๐ Crypt::GPG::Key ๐
Documentation coming soon. same vibe, same waiting. โณ
โญ TODO โญ
the manifest list, the vision board:
- Key server access. ๐๐
- More complete key manipulation interface. ๐ ๏ธ
- Filehandle interface to handle large messages. ๐
๐ BUGS ๐
okay so these are the things that are broken or scary. read them. for real.
- Error checking needs work. ๐ญ
- Some key manipulation functions are missing. ๐ซฅ
- The method call interface is subject to change in future versions. ๐ฎ
- The current implementation will probably eat up all your RAM if you try to operate on huge messages. In future versions, this will be addressed by reading from and returning filehandles, rather than using in-core data. your memory, your problem, for now. ๐
- Methods may break if you don't use ASCII armoring. told you about the armor thing earlier, this is why. ๐
๐ CHANGELOG ๐
okay so this is the receipts section, the lore, the group chat history of this module. it starts with a log line:
$Log: GPG.pm,v $
and then we go revision by revision, oldest drama to newest. buckle up bestie ๐
Revision 1.64 2014/09/18 12:21:25 ashish
- Applied the fix for RT 68339 โ big thanks to Todd Rinaldo for that one ๐
Revision 1.63 2007/04/02 13:34:25 ashish
- Fixed a bug that got introduced by the changes in 1.62 โ and it was about the default signing key, which is like the most main-character setting possible ๐ญ
Revision 1.62 2007/03/31 11:28:12 ashish
- Fixed
debug() - Fixed the regex for the signature line
- Non-forking version of
keygen()(thanks to Greg Hill) โจ - Enabled use of the default Key ID for signing
- Allow for GPG returning 8 or 16 bit KeyIDs (thanks to Roberto Jimenoca)
- Fixed tempfiles being left around after
decrypt() - Changed
exit()toCORE::exit()(suggested by Jonathan R. Baker)
Revision 1.61 2006/12/21 12:36:28 ashish
- Skip tests if
gpgnot found ๐ซถ - Use
File::Specto determinetmpdir. Suggested by Craig Manley.
Revision 1.59 2006/12/19 12:51:54 ashish
- Documentation fixes.
- Removed tests for obsolete 768 bit keys.
- Bugfixes.
- Tested with
gpg 1.4.6.
Revision 1.57 2005/12/15 17:09:17 ashish
- Fixed bug in
decrypt - Fixed small key certification bugs.
Revision 1.50 2005/02/10 12:32:51 cvs
- Overhauled to use
IPC::Runinstead ofExpect. iconic glow-up honestly ๐ - Test suite split up into multiple scripts.
Revision 1.42 2002/12/11 03:33:19 cvs
- Fixed bug in
certify()when trying to certify a revoked key. - Applied
dharris\x40drh.net's patch to allow for varying date formats between gpg versions, and fix time parsing and theCrypt::GPG::Signatureautoloaded accessor functions.
Revision 1.40 2002/09/23 23:01:53 cvs
- Fixed a bug in
keypass() - Documentation fixes.
Revision 1.37 2002/09/21 02:37:49 cvs
- Fixed signing option in
encrypt.
Revision 1.36 2002/09/21 00:03:29 cvs
- Added many tests and fixed a bunch of bugs.
Revision 1.34 2002/09/20 19:07:11 cvs
- Extensively modified formatting to make the code easier to read. All lines are now
< 80chars. - Removed all instances of invoking a shell. ๐ฅ
- Misc. other stuff.
Revision 1.31 2002/09/20 16:38:45 cvs
- Cleaned up
exportandaddkey. Fixed(?)addkeyclobberingtrustdbproblem (thanks tojrray\x40spacemeat.comfor the patch). Added support for signature verification onaddkeypretend. - No calls to
POSIX::tmpnamremain (thanks toradek\x40karnet.plandjrray\x40spacemeat.comfor suggestingFile::Temp).
Revision 1.30 2002/09/20 15:25:47 cvs
- Fixed up tempfile handling and eliminated calls to the shell in
encrypt(),sign()andmsginfo(). Passing all currently defined tests. - Hopefully also fixed signing during encryption and verification of detached signatures. Not tested this yet.
Revision 1.29 2002/09/20 11:19:02 cvs
- Removed hack to
Version:string. Only theComment:string in GPG output is now modified byCrypt::GPG. (Thanks toeisen\x40schlund.defor pointing out the bug here) - Removed code that incorrectly replaced
'PGP MESSAGE'with'PGP SIGNATURE'on detached signatures. (Thanks toddcc\x40mit.edufor pointing this out). - Fixed up
addkey()to properly handle pretend mode and to selectively import only requested key IDs from a key block. parsekeys()now also figures out which keyring a key belongs to.- Added
certify()method, to enable certifying keys. - Added
Crypt::GPG::Signaturemethods โvalidity(),keyid(),time()andtrusted().
๐ AUTHOR ๐
Crypt::GPG is Copyright (c) 2000-2007 Ashish Gulhati <crypt-gpg at neomailbox.com>. All Rights Reserved.
๐ซถ ACKNOWLEDGEMENTS ๐ซถ
Thanks to Barkha, for inspiration; to the GnuPG team; and to everyone who writes free software. fr fr, the whole free software community ate ๐
๐ LICENSE ๐
This code is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
๐ฌ BUGS REPORTS, PATCHES, FEATURE REQUESTS ๐ฌ
Are very welcome. Email crypt-gpg at neomailbox.com. don't be shy bestie, slide into that inbox ๐
and that's a wrap on the whole page!! โจ this was perl v5.42.0, dated 2025-07-25, and you just read GPG(3) โ go forth and encrypt responsibly, mwah ๐
๐
๐ฆ where this page comes from
- fedora 43: perl-Crypt-GPG 1.64-32.fc43 ยท GPL-1.0-or-later OR Artistic-1.0-Perl
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms