Exemplo n.º 1
1
<?php

$plaintext_body = 'Some sensitive order data';
$recipient = '*****@*****.**';
$g = gnupg_init();
gnupg_seterrormode($g, GNUPG_ERROR_WARNING);
// Fingerprint of the recipient's key
$a = gnupg_addencryptkey($g, "5495F0CA9C8F30A9274C2259D7EBE8584CEF302B");
// Fingerprint of the sender's key
$b = gnupg_addsignkey($g, "520D5FC5C85EF4F4F9D94E1C1AF1F7C5916FC221", "passphrase");
$encrypted_body = gnupg_encryptsign($g, $plaintext_body);
mail($recipient, 'Web Site Order', $encrypted_body);
Exemplo n.º 2
0
 private function encrypt($message)
 {
     if ($this->gpgKey === '' && self::GPG_FINGERPRINT === '') {
         return $message;
     }
     if (false === function_exists('gnupg_init')) {
         return $message . PHP_EOL . 'GnuPG Error: gnupg extension is missing.';
     }
     if (false === ($gpg = gnupg_init())) {
         return $message . PHP_EOL . 'GnuPG Error: gnupg_init() failed.';
     }
     if ($this->gpgKey !== '') {
         if (false === gnupg_addencryptkey($gpg, $this->gpgKey)) {
             return $message . PHP_EOL . 'GnuPG Error: gnupg_addencryptkey() failed.';
         }
     }
     $signed = false;
     //		if (self::GPG_FINGERPRINT !== '') {
     //			$sign_key = preg_replace('/[^a-z0-9]/i', '', self::GPG_FINGERPRINT);
     //
     //			if (self::GPG_PASSPHRASE==='')
     //			{
     //				if (false === gnupg_addsignkey($gpg, $sign_key)) {
     //					$message .= PHP_EOL.'GnuPG Error: gnupg_addsignkey1() failed.';
     //				}
     //				else {
     //					$signed = true;
     //				}
     //			}
     //			else
     //			{
     //				if (false === gnupg_addsignkey($gpg, $sign_key, self::GPG_PASSPHRASE)) {
     //					$message .= PHP_EOL.'GnuPG Error: gnupg_addsignkey2() failed.';
     //				}
     //				else {
     //					$signed = true;
     //				}
     //			}
     //
     //		}
     if ($signed === true) {
         if (false === ($back = gnupg_encryptsign($gpg, $message))) {
             return $message . PHP_EOL . 'GnuPG Error: gnupg_encryptsign() failed.';
         }
     } else {
         if (false === ($back = gnupg_encrypt($gpg, $message))) {
             return 'GnuPG Error: gnupg_encrypt() failed.' . PHP_EOL . 'Message has been removed!';
         }
     }
     return $back;
 }