Crypt::GPG
An Object Oriented Interface to GnuPG.
- Provided by: libcrypt-gpg-perl (Version: 1.52-1.1)
- Report a bug
An Object Oriented Interface to GnuPG.
$Revision: 1.52 $ $Date: 2005/02/23 09:12:54 $
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);
The Crypt::GPG module provides access to the functionality of the GnuPG (www.gnupg.org) encryption tool through an object oriented interface.
It provides methods for encryption, decryption, signing, signature verification, key generation, key certification, export and import. Key-server access is on the todo list.
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 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
Either $plaintext or $keylist may be specified as either an arrayref or a simple scalar.
If $plaintext is a 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.
If $pretend is true, it pretends to add the key and creates the key object, but doesn't actually perform the key addition.
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.
Documentation coming soon.
Documentation coming soon.
- Overhauled to use IPC::Run instead of Expect. - 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 revoked a key. - Applied dharris\x40drh.net's patch to allow for varying date formats between gpg versions, and fix time parsing and the Crypt::GPG::Signature autoloaded 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 < 80 chars. - Removed all instances of invoking a shell. - Misc. other stuff.
Revision 1.31 2002/09/20 16:38:45 cvs
- Cleaned up export and addkey. Fixed(?) addkey clobbering trustdb problem (thanks to jrray\x40spacemeat.com for the patch). Added support for signature verification on addkey pretend. - No calls to POSIX::tmpnam remain (thanks to radek\x40karnet.pl and jrray\x40spacemeat.com for suggesting File::Temp).
Revision 1.30 2002/09/20 15:25:47 cvs
- Fixed up tempfile handling and eliminated calls to the shell in encrypt(), sign() and msginfo(). 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 the Comment: string in GPG output is now modified by Crypt::GPG. (Thanks to eisen\x40schlund.de for pointing out the bug here) - Removed code that incorrectly replaced 'PGP MESSAGE' with 'PGP SIGNATURE' on detached signatures. (Thanks to ddcc\x40mit.edu for 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::Signature methods - validity(), keyid(), time() and trusted().
Crypt::GPG is Copyright (c) 2000-2005 Ashish Gulhati <crypt-gpg at neomailbox.com>. All Rights Reserved.
Thanks to Barkha, my sunshine. And to the GnuPG team and everyone who writes free software.
This code is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Are very welcome. Email crypt-gpg at neomailbox.com.