Exemplo n.º 1
0
 /**
  * Re-export the private key to change or disable the passphrase
  *
  * @param KeyPair $keyPair
  * @param string $passphrase Passphrase for opening the key pair
  * @param string $exportPassphrase Passphrase for the exported key pair (NULL for unencrypted private key)
  * @return KeyPair
  * @throws \InvalidArgumentException
  * @throws InvalidPassphraseException
  */
 protected function exportKeyPair($keyPair, $passphrase, $exportPassphrase = null)
 {
     $privateKey = null;
     $encrypted = $exportPassphrase !== null;
     $key = openssl_pkey_get_private($keyPair->getPrivateKey(), $passphrase);
     if ($key === false) {
         throw new InvalidPassphraseException('Invalid passphrase, could not open key', 1300101137);
     }
     openssl_pkey_export($key, $privateKey, $exportPassphrase);
     openssl_free_key($key);
     return new KeyPair($privateKey, $keyPair->getPublicKey(), $encrypted);
 }
Exemplo n.º 2
0
 /**
  * Decrypt the given message using the given key pair
  *
  * @param KeyPair $key
  * @param string $encryptedText
  * @return string
  */
 public function decrypt(KeyPair $key, $encryptedText)
 {
     $rsa = new \Crypt_RSA();
     $rsa->loadKey($key->getPrivateKey());
     return $rsa->decrypt($encryptedText);
 }
 /**
  * Decrypt the given message using the given private key
  *
  * @param KeyPair $key
  * @param string $encryptedText
  * @throws DecryptionException
  * @return string
  */
 public function decrypt(KeyPair $key, $encryptedText)
 {
     $encryptedText = base64_decode($encryptedText);
     $success = openssl_private_decrypt($encryptedText, $result, $key->getPrivateKey());
     if ($success !== TRUE) {
         throw new DecryptionException('Decryption failed');
     }
     return $result;
 }
 /**
  * Decrypt the given message using the given key pair
  *
  * @abstract
  * @param KeyPair $key
  * @param string $encryptedText
  * @return string
  */
 public function decrypt(KeyPair $key, $encryptedText)
 {
     return $this->rsaUtil($key->getPrivateKey(), $encryptedText, 'decrypt');
 }