Skip to content

Repository files navigation

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('[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.

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 <[email protected]>'));

?>

About

Encrypt/decrypt PGP messages with PHP

Resources

Stars

95 stars

Watchers

16 watching

Forks

Releases

Packages

Used by

Contributors

Languages