예제 #1
0
파일: Rsa.php 프로젝트: tejdeeps/tejcs.com
 /**
  * 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);
 }
예제 #2
0
파일: Rsa.php 프로젝트: necrogami/zf2
    /**
     * 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;
        }
    }
예제 #3
0
 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());
 }