PHP code example of zbateson / mmp-crypt-gpg

1. Go to this page and download the library: Download zbateson/mmp-crypt-gpg library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

zbateson / mmp-crypt-gpg example snippets


use ZBateson\MailMimeParser\Message;
use ZBateson\MmpCryptGpg\GpgPear;
use ZBateson\MmpCryptGpg\PgpMimeMessage;

$message = Message::from($rawEmail, false);

$cryptGpg = new \Crypt_GPG();
$cryptGpg->addEncryptKey('[email protected]');
$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;

$cryptGpg = new \Crypt_GPG();
$cryptGpg->addSignKey('[email protected]');
$crypt = new GpgPear($cryptGpg);

$signed = PgpMimeMessage::sign($message, $crypt);

$cryptGpg = new \Crypt_GPG();
$cryptGpg->addSignKey('[email protected]');
$cryptGpg->addEncryptKey('[email protected]');
$crypt = new GpgPear($cryptGpg);

$result = PgpMimeMessage::signAndEncrypt($message, $crypt);

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());