public function decrypt($string)
 {
     $user = new User();
     $gpg = new gnupg();
     $gpg->adddecryptkey($user->getPrivatekey());
     $decryptedString = $gpg->decrypt($string);
     return $decryptedString;
 }
Exemplo n.º 2
0
 /**
  * GnuPG decrypt and verify a message using the recipient private key
  * Returns an array in the format: array (0 => $message, 1 => $signatures)
  * 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 private key ring
  * @param string $recipient Recipient Indentity (e.g. email address)
  * @param string $recipientKey Recipient Secret Key
  * @param string $message Message to decrypt
  * @return array
  */
 public static function _verifyGnuPG($recipient, $recipientKey, $message)
 {
     // Create new GnuPG object
     $gpg = new \gnupg();
     // Set error mode
     $gpg->seterrormode(\gnupg::ERROR_EXCEPTION);
     // Add the recipient decryption key
     $gpg->adddecryptkey($recipient, $recipientKey);
     // Set decrpyted string
     $decrypted = '';
     // Set decrypted and verification data
     $return[1] = $gpg->decryptverify($message, $decrypted);
     // For each signature
     foreach ($return[1] as $key => &$signature) {
         // Get further user data
         $signature['user'] = $gpg->keyinfo($signature['fingerprint']);
     }
     // Add decrypted data to return array
     $return[0] = $decrypted;
     // Return decryption data
     return $return;
 }