zbateson / mmp-crypt-gpg
PGP/MIME implementation of zbateson/mmp-crypt using PEAR Crypt_GPG
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/zbateson/mmp-crypt-gpg
Requires
- php: >=8.1
- guzzlehttp/psr7: ^2.0
- pear/crypt_gpg: ^1.6
- psr/http-message: ^2.0
- zbateson/mmp-crypt: ^1.0
Requires (Dev)
- phpunit/phpunit: ^10.0 || ^11.0
This package is auto-updated.
Last update: 2026-02-13 19:04:37 UTC
README
PGP/MIME encryption, decryption, signing, and verification for zbateson/mail-mime-parser using PEAR's Crypt_GPG.
composer require zbateson/mmp-crypt-gpg
Sponsors
A huge thank you to all my sponsors. <3
If this project's helped you, please consider sponsoring me.
Requirements
PHP 8.1 or newer with the gpg binary available on the system, and zbateson/mail-mime-parser 4.x. A configured GnuPG keyring with the appropriate keys imported is also required — see the GnuPG documentation for details on setting up your keyring.
Description
This package provides a PGP/MIME implementation of zbateson/mmp-crypt using PEAR's Crypt_GPG. It supports:
- Encrypting and decrypting
multipart/encrypted; protocol="application/pgp-encrypted"messages - Signing and verifying detached
application/pgp-signaturesignatures - Composing PGP/MIME messages via the
PgpMimeMessagestatic API (encrypt, sign, sign-then-encrypt)
All operations use file-based I/O via temp files, so large messages are handled without loading them entirely into memory.
Usage
Composing an encrypted message
use ZBateson\MailMimeParser\Message; use ZBateson\MmpCryptGpg\GpgPear; use ZBateson\MmpCryptGpg\PgpMimeMessage; $message = Message::from($rawEmail, false); $cryptGpg = new \Crypt_GPG(); $cryptGpg->addEncryptKey('recipient@example.com'); $crypt = new GpgPear($cryptGpg); // Encrypt -- returns a new IMimePart with multipart/encrypted structure $encrypted = PgpMimeMessage::encrypt($message, $crypt); // The outer Subject defaults to "..." to hide the real subject echo (string) $encrypted;
Composing a signed message
$cryptGpg = new \Crypt_GPG(); $cryptGpg->addSignKey('sender@example.com'); $crypt = new GpgPear($cryptGpg); $signed = PgpMimeMessage::sign($message, $crypt);
Sign-then-encrypt
$cryptGpg = new \Crypt_GPG(); $cryptGpg->addSignKey('sender@example.com'); $cryptGpg->addEncryptKey('recipient@example.com'); $crypt = new GpgPear($cryptGpg); $result = PgpMimeMessage::signAndEncrypt($message, $crypt);
Decrypting a parsed message
use ZBateson\MmpCryptGpg\GpgPear; $cryptGpg = new \Crypt_GPG(); // Keys must be in the GnuPG keyring for decryption $crypt = new GpgPear($cryptGpg); $decrypted = $crypt->decrypt($encryptedPart->getContentStream());
License
BSD licensed - please see license agreement.