['sha256', 32], 'HS384' => ['sha384', 48], 'HS512' => ['sha512', 64], default => throw new \InvalidArgumentException('Unsupported JWT algorithm: ' . $jwtAlgo, 1774954888), }; return new Key( hash_hkdf( algo: $hashAlgo, key: $baseKey, length: $length, info: $context, ), $jwtAlgo ); } private static function createSigningKeyFromEncryptionKey(string $context = self::class): Key { return self::deriveKey( $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] ?? '', $context === '' ? self::class : $context ); } private static function createSigningSecret(SigningSecretInterface $secret, string $context = self::class): Key { return self::deriveKey( $secret->getSigningSecret(), $context === '' ? self::class : $context ); } private static function encodeHashSignedJwt(array $payload, Key $key, ?SecretIdentifier $identifier = null): string { $keyId = $identifier !== null ? json_encode($identifier) : null; return JWT::encode($payload, $key->getKeyMaterial(), $key->getAlgorithm(), $keyId); } private static function decodeJwt(string $jwt, Key $key, bool $associative = false): \stdClass|array { $payload = JWT::decode($jwt, $key); return $associative ? json_decode(json_encode($payload), true) : $payload; } private static function decodeJwtHeader(string $jwt, string $property): mixed { $parts = explode('.', $jwt); if (count($parts) !== 3) { return null; } $headerRaw = JWT::urlsafeB64Decode($parts[0]); if (($header = JWT::jsonDecode($headerRaw)) === null) { return null; } return $header->{$property} ?? null; } }