예제 #1
0
파일: Rsa.php 프로젝트: tejdeeps/tejcs.com
 /**
  * Decrypt with private/public key
  *
  * $data can be encoded in base64 or not. $mode sets how the input must be processed:
  *  - MODE_AUTO: Check if the $signature is encoded in base64. Not recommended for performance.
  *  - MODE_BASE64: Decode $data using base64 algorithm.
  *  - MODE_RAW: $data is not encoded.
  *
  * @param  string          $data
  * @param  Rsa\AbstractKey $key
  * @param  int             $mode Input encoding
  * @return string
  * @throws Rsa\Exception\InvalidArgumentException
  * @see Rsa::MODE_AUTO
  * @see Rsa::MODE_BASE64
  * @see Rsa::MODE_RAW
  */
 public function decrypt($data, Rsa\AbstractKey $key = null, $mode = self::MODE_AUTO)
 {
     if (null === $key) {
         $key = $this->options->getPrivateKey();
     }
     if (null === $key) {
         throw new Exception\InvalidArgumentException('No key specified for the decryption');
     }
     switch ($mode) {
         case self::MODE_AUTO:
             // check if data is encoded in Base64
             $output = base64_decode($data, true);
             if (false !== $output && $data === base64_encode($output)) {
                 $data = $output;
             }
             break;
         case self::MODE_BASE64:
             $data = base64_decode($data);
             break;
         case self::MODE_RAW:
         default:
             break;
     }
     return $key->decrypt($data);
 }
예제 #2
0
 /**
  * Decrypt with private/public key
  *
  * @param  string          $data
  * @param  Rsa\AbstractKey $key
  * @return string
  * @throws Rsa\Exception\InvalidArgumentException
  */
 public function decrypt($data, Rsa\AbstractKey $key = null)
 {
     if (null === $key) {
         $key = $this->options->getPrivateKey();
     }
     if (null === $key) {
         throw new Exception\InvalidArgumentException('No key specified for the decryption');
     }
     return $key->decrypt($data);
 }
예제 #3
0
파일: Rsa.php 프로젝트: necrogami/zf2
    /**
     * Decrypt
     *
     * @param string          $data
     * @param Rsa\AbstractKey $key
     * @param string          $format
     * @return string
     * @throws Rsa\Exception\RuntimeException
     */
    public function decrypt($data, Rsa\AbstractKey $key = null, $format = null)
    {
        if ($format == self::FORMAT_BASE64) {
            $data = base64_decode($data);
        }

        if (null === $key) {
            $key = $this->options->getPrivateKey();
        }

        return $key->decrypt($data);
    }
예제 #4
0
파일: Rsa.php 프로젝트: Baft/Zend-Form
 /**
  * Decrypt with private/public key
  *
  * @param  string          $data
  * @param  Rsa\AbstractKey $key
  * @return string
  * @throws Rsa\Exception\InvalidArgumentException
  */
 public function decrypt($data, Rsa\AbstractKey $key = null)
 {
     if (null === $key) {
         $key = $this->options->getPrivateKey();
     }
     if (null === $key) {
         throw new Exception\InvalidArgumentException('No key specified for the decryption');
     }
     // check if data is encoded in Base64
     $output = base64_decode($data, true);
     if (false !== $output) {
         $data = $output;
     }
     return $key->decrypt($data);
 }
예제 #5
0
 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()));
 }
예제 #6
0
 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');
     }
 }