/**
  * Writes a key pair to a file
  *
  * @param \TYPO3\Deploy\Encryption\KeyPair $keyPair
  * @param string $filename
  * @return void
  * @author Christopher Hlubek <*****@*****.**>
  */
 protected function writeKeyPair(\TYPO3\Deploy\Encryption\KeyPair $keyPair, $filename)
 {
     $data = json_encode(array('encrypted' => $keyPair->isEncrypted(), 'privateKey' => $keyPair->getPrivateKey(), 'publicKey' => $keyPair->getPublicKey()));
     file_put_contents($filename, $data);
 }
 /**
  * Re-export the private key to change or disable the passphrase
  *
  * @param \TYPO3\Deploy\Encryption\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 \TYPO3\Deploy\Encryption\KeyPair
  * @author Christopher Hlubek <*****@*****.**>
  */
 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 \TYPO3\Deploy\Encryption\InvalidPassphraseException('Invalid passphrase, could not open key', 1300101137);
     }
     openssl_pkey_export($key, $privateKey, $exportPassphrase);
     openssl_free_key($key);
     return new \TYPO3\Deploy\Encryption\KeyPair($privateKey, $keyPair->getPublicKey(), $encrypted);
 }