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

1.0.0 2026-02-13 19:01 UTC

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.

Total Downloads Latest Stable Version

composer require zbateson/mmp-crypt-gpg

Sponsors

SecuMailer

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-signature signatures
  • Composing PGP/MIME messages via the PgpMimeMessage static 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.