public function testConstructorLoadsPassphrasedKeys() { if (!$this->openSslConf) { $this->markTestSkipped('No openssl.cnf found or defined; cannot generate keys'); } $rsa = new Rsa(); $keys = $rsa->generateKeys(array( 'config' => $this->openSslConf, 'private_key_bits' => 512, 'pass_phrase' => '0987654321' )); try { $rsa = new Rsa(new RsaOptions(array( 'pass_phrase' => '0987654321', 'pem_string' => $keys->privateKey->toString() ))); } catch (Exception\ExceptionInterface $e) { $this->fail('Passphrase loading failed of a private key'); } }
/** * Sign a request * * @param array $params * @param null|string $method * @param null|string $url * @return string */ public function sign(array $params, $method = null, $url = null) { $rsa = new RsaEnc(new RsaEncOptions(array('hash_algorithm' => $this->_hashAlgorithm, 'bnary_output' => true))); return $rsa->sign($this->_getBaseSignatureString($params, $method, $url), $this->_key); }
public function testVerifyCorruptRaw() { $data = 'sMHpp3u6DNecIm5RIkDD3xyKaH6qqP8roUWDs215iOGHehfK1ypqwoETKNP7NaksGS2C1Up813ixlGXkipPVbQ=='; $this->assertFalse($this->rsa->verify('1234567890', $data, null, Rsa::MODE_RAW)); }
public function testRsaLoadsPassphrasedKeys() { $rsaOptions = new RsaOptions(array('pass_phrase' => '0987654321')); $rsaOptions->generateKeys(array('config' => $this->userOpenSslConf, 'private_key_bits' => 512)); Rsa::factory(array('pass_phrase' => '0987654321', 'private_key' => $rsaOptions->getPrivateKey()->toString())); }
/** * {@inheritdoc} */ public function encrypt($value) { return $this->zendRsa->encrypt($value); }
public function testRsaLoadsPassphrasedKeys() { $rsaOptions = new RsaOptions(array('pass_phrase' => '0987654321')); $rsaOptions->generateKeys(array('config' => $this->userOpenSslConf, 'private_key_bits' => 512)); try { $rsa = Rsa::factory(array('pass_phrase' => '0987654321', 'private_key' => $rsaOptions->getPrivateKey()->toString())); } catch (Exception\RuntimeException $e) { $this->fail('Passphrase loading of a private key failed'); } }
/** * Load a key pair from disk * @param string $name * @param string $passPhrase * @return void */ protected function loadKey($name, $passPhrase = NULL) { $list = $this->getKeyList(); $hash = $list[$name]['file']; $base = $this->options->getBasePath() . DIRECTORY_SEPARATOR; $private = $base . $hash; $public = $private . '.pub'; $options = array('private_key' => $private, 'public_key' => $public, 'pass_phrase' => $passPhrase, 'binary_output' => $list[$name]['binaryOutput'], 'hashAlgorithm' => $list[$name]['hashAlgorithm']); if ($this->requiresPassPhrase($name) && empty($passPhrase)) { /** * Do not load the private key so we can still perform encryption * with the public key */ unset($options['private_key'], $options['pass_phrase']); } try { $rsa = Rsa::factory($options); } catch (ZendException $e) { throw new Exception\RuntimeException('Failed to load key pair', $e); } $this->keys[$name] = $rsa; }