예제 #1
0
파일: Rsa.php 프로젝트: tejdeeps/tejcs.com
 /**
  * Verify signature with public key
  *
  * $signature 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 $signature using base64 algorithm.
  *  - MODE_RAW: $signature is not encoded.
  *
  * @param  string $data
  * @param  string $signature
  * @param  null|Rsa\PublicKey $publicKey
  * @param  int                $mode Input encoding
  * @return bool
  * @throws Rsa\Exception\RuntimeException
  * @see Rsa::MODE_AUTO
  * @see Rsa::MODE_BASE64
  * @see Rsa::MODE_RAW
  */
 public function verify($data, $signature, Rsa\PublicKey $publicKey = null, $mode = self::MODE_AUTO)
 {
     if (null === $publicKey) {
         $publicKey = $this->options->getPublicKey();
     }
     switch ($mode) {
         case self::MODE_AUTO:
             // check if data is encoded in Base64
             $output = base64_decode($signature, true);
             if (false !== $output && $signature === base64_encode($output)) {
                 $signature = $output;
             }
             break;
         case self::MODE_BASE64:
             $signature = base64_decode($signature);
             break;
         case self::MODE_RAW:
         default:
             break;
     }
     $result = openssl_verify($data, $signature, $publicKey->getOpensslKeyResource(), $this->options->getOpensslSignatureAlgorithm());
     if (-1 === $result) {
         throw new Exception\RuntimeException('Can not verify signature; openssl ' . $this->getOpensslErrorString());
     }
     return $result === 1;
 }
예제 #2
0
 /**
  * Verify signature with public key
  *
  * @param  string $data
  * @param  string $signature
  * @param  null|Rsa\PublicKey $publicKey
  * @return bool
  * @throws Rsa\Exception\RuntimeException
  */
 public function verify($data, $signature, Rsa\PublicKey $publicKey = null)
 {
     if (null === $publicKey) {
         $publicKey = $this->options->getPublicKey();
     }
     $result = openssl_verify($data, $signature, $publicKey->getOpensslKeyResource(), $this->options->getOpensslSignatureAlgorithm());
     if (-1 === $result) {
         throw new Exception\RuntimeException('Can not verify signature; openssl ' . openssl_error_string());
     }
     return $result === 1;
 }
예제 #3
0
파일: Rsa.php 프로젝트: Baft/Zend-Form
 /**
  * Verify signature with public key
  *
  * @param  string $data
  * @param  string $signature
  * @param  null|Rsa\PublicKey $publicKey
  * @return bool
  * @throws Rsa\Exception\RuntimeException
  */
 public function verify($data, $signature, Rsa\PublicKey $publicKey = null)
 {
     if (null === $publicKey) {
         $publicKey = $this->options->getPublicKey();
     }
     // check if signature is encoded in Base64
     $output = base64_decode($signature, true);
     if (false !== $output) {
         $signature = $output;
     }
     $result = openssl_verify($data, $signature, $publicKey->getOpensslKeyResource(), $this->options->getOpensslSignatureAlgorithm());
     if (-1 === $result) {
         throw new Exception\RuntimeException('Can not verify signature; openssl ' . openssl_error_string());
     }
     return $result === 1;
 }