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.
To install using Composer
$ composer require pear/crypt_gpg
To test, run
$ vendor/bin/phpunit tests
<?php
use Crypt/GPG;
$gpg = new GPG([
'homedir' => '/home/alec/.gnupg',
'binary' => '/usr/bin/gpg',
]);
$gpg->addEncryptKey('[email protected]');
$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.
<?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 <[email protected]>'));
?>