/** * * @see \JWX\JWS\SignatureAlgorithm::validateSignature() * @throws \RuntimeException For generic errors * @return bool */ public function validateSignature($data, $signature) { $key = openssl_pkey_get_public($this->_publicKey->toPEM()->string()); if (!$key) { throw new \RuntimeException("openssl_pkey_get_public() failed: " . $this->_getLastOpenSSLError()); } $result = @openssl_verify($data, $signature, $key, $this->_mdMethod()); if (false === $result || -1 == $result) { throw new \RuntimeException("openssl_verify() failed: " . $this->_getLastOpenSSLError()); } return $result == 1; }
/** * Constructor * * @param JWKParameter ...$params * @throws \UnexpectedValueException If missing required parameter */ public function __construct(JWKParameter ...$params) { parent::__construct(...$params); foreach (self::MANAGED_PARAMS as $name) { if (!$this->has($name)) { throw new \UnexpectedValueException("Missing '{$name}' parameter."); } } if ($this->keyTypeParameter()->value() != KeyTypeParameter::TYPE_EC) { throw new \UnexpectedValueException("Invalid key type."); } }