Search by

php-privacy / openpgp

nguyennv

PHP Privacy - The OpenPGP library in PHP language

Package info

github.com/web-of-trust/php-privacy

pkg:composer/php-privacy/openpgp

Statistics

Installs: 73 972

Dependents: 0

Suggesters: 0

Stars: 10

Open Issues: 0

2.2.20 2026-11-30 10:49 UTC

README

PHP Privacy is an implementation of the OpenPGP standard in PHP language. It implements RFC 9580 and provides encryption with public key or symmetric cryptographic algorithms, digital signatures, compression, and key management.

Requirement

  • PHP 8.1.x or later,
  • phpseclib library provides cryptography algorithms,
  • Argon2 for Argon2 string-to-key,
  • (optional) PHPUnit to run tests,

Features

Installation

Via Composer

$ composer require php-privacy/openpgp

or just add it to your composer.json file directly.

{
    "require": {
        "php-privacy/openpgp": "^2.2"
    }
}

Configuration

Settings such as the preferred algorithms, the RFC preset and the limits for reading messages are static methods of OpenPGP\Common\Config. Set them once, before you generate keys or read and write messages. The defaults suit most uses; on a server that reads messages from others, consider lowering the limit on decompressed data. See docs/configuration.md for every setting and docs/reading-messages-from-others.md for the limits.

Basic usage of PHP Privacy

Sign and verify cleartext message

<?php declare(strict_types=1);

require_once 'vendor/autoload.php';

use OpenPGP\OpenPGP;

$armoredPublicKey = '-----BEGIN PGP PUBLIC KEY BLOCK-----';
$armoredPrivateKey = '-----BEGIN PGP PRIVATE KEY BLOCK-----';
$passphrase = 'Your passphrase';

$publicKey = OpenPGP::readPublicKey($armoredPublicKey);
$privateKey = OpenPGP::decryptPrivateKey($armoredPrivateKey, $passphrase);
$cleartextMessage = OpenPGP::createCleartextMessage('Hello, PHP Privacy!');
$signedMessage = $cleartextMessage->sign([$privateKey]);
$verifications = $signedMessage->verify([$publicKey]);

Licensing

BSD 3-Clause

For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.