Skip to content

Latest commit

 

History

History
62 lines (47 loc) · 1.33 KB

README.md

File metadata and controls

62 lines (47 loc) · 1.33 KB

Crypt_GPG

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

?>