Jose\Util\RSA::verify PHP Method

verify() public static method

Verifies a signature.
public static verify ( RSAKey $key, string $message, string $signature, string $hash ) : boolean
$key Jose\KeyConverter\RSAKey
$message string
$signature string
$hash string
return boolean
    public static function verify(RSAKey $key, $message, $signature, $hash)
    {
        Assertion::string($message);
        Assertion::string($signature);
        Assertion::string($hash);
        Assertion::inArray($hash, ['sha256', 'sha384', 'sha512']);
        Assertion::eq(strlen($signature), $key->getModulusLength());
        $modBits = 8 * $key->getModulusLength();
        $s2 = self::convertOctetStringToInteger($signature);
        $m2 = self::getRSAVP1($key, $s2);
        Assertion::isInstanceOf($m2, BigInteger::class);
        $em = self::convertIntegerToOctetString($m2, $modBits >> 3);
        return self::verifyEMSAPSS($message, $em, $modBits - 1, Hash::$hash());
    }

Usage Example

Example #1
0
 /**
  * {@inheritdoc}
  */
 public function verify(JWKInterface $key, $input, $signature)
 {
     $this->checkKey($key);
     $pub = RSAKey::toPublic(new RSAKey($key));
     if ($this->getSignatureMethod() === self::SIGNATURE_PSS) {
         return JoseRSA::verify($pub, $input, $signature, $this->getAlgorithm());
     } else {
         return 1 === openssl_verify($input, $signature, $pub->toPEM(), $this->getAlgorithm());
     }
 }