pear/crypt_gpg

Provides an object oriented interface to the GNU Privacy Guard (GnuPG). It requires the GnuPG executable to be on the system.

Maintainers

Package info

github.com/pear/Crypt_GPG

pkg:composer/pear/crypt_gpg

Transparency log

Statistics

Installs: 4 690 564

Dependents: 10

Suggesters: 1

Stars: 95

Open Issues: 0

v2.0.0 2026-08-03 13:33 UTC

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>'));

?>