setTimestamp($payload['exp'])->format(\DateTime::ISO8601) ) ); } } public static function validateSignature(string $alg, string $secret, string $encodedHeader, string $encodedPayload, string $encodedSignature) : void { $algorithm = JsonWebTokenAlgorithmEnum::fromString($alg); static::validateAlgorithm($algorithm); $decodedSignature = JsonWebTokenDecoder::base64url_decode($encodedSignature); list($algo, $method, ) = $algorithm->phpAlgoMethods(); switch($method) { case 'hash_hmac': $compare = hash_hmac($algo, sprintf("%s.%s", $encodedHeader, $encodedPayload), $secret, true); break; } if ( ($compare ?? null) !== $decodedSignature) { throw new JsonWebTokenDecodingError( sprintf("Given signature (%s) do not match computed signature (%s)", $encodedSignature, JsonWebTokenEncoder::base64url_encode($compare)) ); } } public static function validateAlgorithm(JsonWebTokenAlgorithmEnum $algorithm) : void { $algorithm->assessOperability(); } }