hash($key, $input), $signature); } public function hash(JWK $key, string $input): string { $k = $this->getKey($key); return hash_hmac($this->getHashAlgorithm(), $input, $k, true); } protected function getKey(JWK $key): string { if (! in_array($key->get('kty'), $this->allowedKeyTypes(), true)) { throw new InvalidArgumentException('Wrong key type.'); } if (! $key->has('k')) { throw new InvalidArgumentException('The key parameter "k" is missing.'); } $k = $key->get('k'); if (! is_string($k)) { throw new InvalidArgumentException('The key parameter "k" is invalid.'); } return Base64UrlSafe::decode($k); } abstract protected function getHashAlgorithm(): string; }