Exemplo n.º 1
0
 /**
  * Encrypt the body of an email.
  *
  * @param Message $message
  * @return Message
  */
 public function decrypt(Message $message) : Message
 {
     $gnupg = new \Crypt_GPG($this->options);
     $gnupg->addDecryptKey($this->serverKeyFingerprint);
     // Replace the message with its encrypted counterpart
     $decrypted = $gnupg->decrypt($message->getBodyText());
     return $message->setBody($decrypted);
 }
Exemplo n.º 2
0
 /**
  * Decrypt and verify given string
  * 
  * @param string $string
  * @param string $keyPassword
  * @param string $keyID
  * @return array|false
  */
 public static function decryptAndVerify($string, $keyPassword = null, $keyID = null)
 {
     $gpg = new Crypt_GPG();
     if ($keyID === null) {
         $keyID = ConfigManager::getConfig("Crypto", "GPG")->AuxConfig->defaultKey;
     }
     if ($keyPassword === null) {
         $keyPassword = ConfigManager::getConfig("Crypto", "GPG")->AuxConfig->defaultKeyPasswd;
     }
     $gpg->addDecryptKey($keyID, $keyPassword);
     $result = $gpg->decryptAndVerify($string);
     if (empty($result['data']) and empty($result['signatures'])) {
         return false;
     }
     if (isset($result['signatures'][0])) {
         $result['signature'] = $result['signatures'][0]->isValid();
         unset($result['signatures']);
     }
     return $result;
 }