/** * Encrypt with private/public key * * @param string $data * @param Rsa\AbstractKey $key * @return string * @throws Rsa\Exception\InvalidArgumentException */ public function encrypt($data, Rsa\AbstractKey $key = null) { if (null === $key) { $key = $this->options->getPublicKey(); } if (null === $key) { throw new Exception\InvalidArgumentException('No key specified for the decryption'); } $encrypted = $key->encrypt($data); if ($this->options->getBinaryOutput()) { return $encrypted; } return base64_encode($encrypted); }
/** * Encrypt * * @param string $data * @param Rsa\AbstractKey $key * @param string $format * @return string * @throws Rsa\Exception\RuntimeException */ public function encrypt($data, Rsa\AbstractKey $key = null, $format = null) { if (null === $key) { $key = $this->options->getPublicKey(); } $encrypted = $key->encrypt($data); if ($format == self::FORMAT_BASE64) { return base64_encode($encrypted); } else { return $encrypted; } }
public function testKeyGenerationWithUserOpensslConfig() { $rsaOptions = new RsaOptions(); $rsaOptions->generateKeys(array('config' => $this->userOpenSslConf, 'private_key_bits' => 512)); $this->assertInstanceOf('Zend\\Crypt\\PublicKey\\Rsa\\PrivateKey', $rsaOptions->getPrivateKey()); $this->assertInstanceOf('Zend\\Crypt\\PublicKey\\Rsa\\PublicKey', $rsaOptions->getPublicKey()); }