Esempio n. 1
0
 /**
  * @inheritdoc
  */
 public function encrypt($unencrypted)
 {
     $encrypted = $this->gpg->sign($unencrypted);
     if (!$encrypted) {
         throw EncryptionException::notEncrypted($this->gpg->geterror());
     }
     return $encrypted;
 }
Esempio n. 2
0
 /**
  * @inheritdoc
  */
 public function decrypt($encrypted)
 {
     $decrypted = $this->gpg->decrypt($encrypted);
     if (!$decrypted) {
         throw EncryptionException::notDecrypted($this->gpg->geterror());
     }
     return $decrypted;
 }
Esempio n. 3
0
 /**
  * @inheritdoc
  */
 public function decrypt($encrypted)
 {
     $decrypted = '';
     $this->signature = $this->gpg->decryptverify($encrypted, false, $decrypted);
     if (!$decrypted || !$this->signature) {
         throw EncryptionException::notDecryptedAndVerified($this->gpg->geterror());
     }
     return $decrypted;
 }
Esempio n. 4
0
 /**
  * @inheritdoc
  */
 public function decrypt($encrypted)
 {
     $decrypted = '';
     $signature = null;
     $info = $this->gpg->verify($encrypted, false, $decrypted);
     if (!$info) {
         throw EncryptionException::notVerified($this->gpg->geterror());
     }
     return $decrypted;
 }
 /**
  * @param string $serverEncryptKey
  * @param string $serverSignKey
  * @throws EncryptionException
  */
 private function init($serverEncryptKey = null, $serverSignKey = null)
 {
     $token = $this->sc->getToken();
     if ($token instanceof TokenInterface && $token->getUser() instanceof GnuPGUserInterface) {
         $encryptKey = $token->getUser()->getPublicGnuPGKeyFingerprint() ?: $serverEncryptKey;
         $signKey = $token->getUser()->getPublicSignGnuPGKeyFingerprint() ?: $serverSignKey;
     } else {
         $encryptKey = $serverEncryptKey;
         $signKey = $serverSignKey;
     }
     $this->gpg = new \gnupg();
     if (!is_null($encryptKey)) {
         $this->gpg->addencryptkey($encryptKey);
         $this->ability |= EncryptionAbility::ENCRYPT;
     }
     if (!is_null($signKey)) {
         $this->gpg->addsignkey($signKey);
         $this->ability |= EncryptionAbility::SIGN;
     }
     if (EncryptionAbility::NONE === $this->ability) {
         throw EncryptionException::missingConfiguration();
     }
 }