pear / crypt_gpg
Provides an object oriented interface to the GNU Privacy Guard (GnuPG). It requires the GnuPG executable to be on the system.
v2.0.0
2026-08-03 13:33 UTC
Requires
- php: >=8.1
Requires (Dev)
- ext-posix: *
- friendsofphp/php-cs-fixer: ^3.95
- phpstan/phpstan: ^2.2
- phpunit/phpunit: ^10
Suggests
- ext-posix: May require the posix PHP extension
README
Crypt_GPG is a PHP package to interact with the GNU Privacy Guard (GnuPG). GnuPG is a free and open-source implementation of the OpenPGP protocol, providing key management, data encryption and data signing. Crypt_GPG provides an object-oriented API for performing OpenPGP actions using GnuPG.
Documentation
Installing
To install using Composer
$ composer require pear/crypt_gpg
Testing
To test, run
$ vendor/bin/phpunit tests
Quick Example
<?php use Crypt/GPG; $gpg = new GPG([ 'homedir' => '/home/alec/.gnupg', 'binary' => '/usr/bin/gpg', ]); $gpg->addEncryptKey('test@example.com'); $data = $gpg->encrypt('my secret data'); ?>
The GPG is the main class that provides most of the API. It will return data using
Key, SubKey, UserId, Signature objects.
Additionally you can use KeyEditor or KeyGenerator for functionality not covered by GPG.
Key Generation
<?php use Crypt/GPG/KeyGenerator; use Crypt/GPG/UserId; $keygen = new KeyGenerator([ 'homedir' => '/home/alec/.gnupg', 'binary' => '/usr/bin/gpg', ]); $key = $keygen ->setExpirationDate('+10 years') ->generateKey(new UserId('Test Keypair <test@example.com>')); ?>