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.
- PHP 8.1.x or later,
- phpseclib library provides cryptography algorithms,
- Argon2 for Argon2 string-to-key,
- (optional) PHPUnit to run tests,
- Support data signing & encryption.
- Support key management: key generation, key reading, key decryption.
- Support public-key algorithms: RSA, ECDSA, EdDSA and ECDH.
- Support symmetric ciphers: Blowfish, Twofish, AES, Camellia.
- Support AEAD ciphers: EAX, OCB, GCM.
- Support hash algorithms: SHA-256, SHA-384, SHA-512, SHA-224, SHA3-256, SHA3-512.
- Support compression algorithms: Zip, Zlib, BZip2.
- Support ECC curves: secp256r1, secp384r1, secp521r1, brainpoolP256r1, brainpoolP384r1, brainpoolP512r1, Curve25519, Curve448, Ed25519, Ed448.
- Support public-key algorithms, symmetric ciphers & hash algorithms for signature verification & message decryption (backward compatibility): DSA, ElGamal, TripleDES, IDEA, CAST5, MD5, SHA-1, RIPEMD-160.
Via Composer
$ composer require php-privacy/openpgp
or just add it to your composer.json
file directly.
{
"require": {
"php-privacy/openpgp": "^2.0"
}
}
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]);
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.