Esempio n. 1
-1
 /**
  * GnuPG encrypt a message using the recipient public key and optionally sign
  * http://devzone.zend.com/article/3753-Using-GnuPG-with-PHP
  * NOTE: GnuPG must be installed and configured with PHP.
  *       The recipient must be in your public key ring
  * @param string $recipient Recipient Indentity (e.g. email address)
  * @param string $message Message to encrypt
  * @param string $sender Sender Identity
  * @param string $senderKey Key Sender Secret Key (Only required if signing)
  * @param boolean $binary Output in binary (non-ASCII armored)
  * @return string
  */
 public static function _encryptGnuPG($recipient, $message, $sender = FALSE, $senderKey = '', $binary = FALSE)
 {
     // Create new GnuPG object
     $gpg = new \gnupg();
     // Set error mode
     $gpg->seterrormode(\gnupg::ERROR_EXCEPTION);
     // If binary
     if ($binary) {
         // Turn off armored mode
         $gpg->setarmor(0);
     }
     // Add the recipient encryption key
     $gpg->addencryptkey($recipient);
     // If there is a sender
     if ($sender !== FALSE) {
         // Add signature
         $gpg->addsignkey($sender, $senderKey);
         // Return encrypted and signed data
         return $gpg->encryptsign($message);
     }
     // Return encrypted data
     return $gpg->encrypt($message);
 }