0Pricing
Spring Security 6 & JWT Authentication · Lektion

Signaturschlüssel rotieren und verwalten

Lernen Sie, warum und wie Sie JWT-Signaturschlüssel sicher rotieren – mit Schlüssel-IDs (kid), JWK-Sets und sich überschneidenden Gültigkeitszeiträumen, um Ausfallzeiten zu vermeiden.

Signaturschlüssel rotieren und verwalten ist eine kostenlose Spring Security 6 & JWT Authentication-Lektion auf CoddyKit. Dies ist Lektion 4 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Spring Security 6 & JWT Authentication-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Spring Security 6 & JWT Authentication-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

Why Rotate Keys?

A signing key is the secret that proves a JWT is genuine. If it leaks, an attacker can forge tokens. Key rotation replaces keys periodically so a compromised key has a limited lifetime.

The Rotation Challenge

You cannot simply swap the key: tokens signed with the old key are still valid until they expire. The server must accept the old and new keys at the same time during a transition window.

The kid Header

The JWT header can carry a kid (key ID). It tells the verifier which key signed this token, so the server can look up the right key among several.

{
  'alg': 'RS256',
  'typ': 'JWT',
  'kid': 'key-2024-06'
}

Signing With a kid

When you mint a token, stamp the current key's id into the header so verifiers can find the matching public key later.

const token = sign(payload, privateKey, {
  algorithm: 'RS256',
  keyid: 'key-2024-06'
});

Keeping a Key Map

The server holds a map of kid to key. During rotation it contains both the retiring key and the new key.

const keys = {
  'key-2024-06': newPublicKey,
  'key-2024-03': oldPublicKey
};

Verifying by kid

On verification, read the kid from the header, select the key, then validate the signature against it.

const header = decodeHeader(token);
const key = keys[header.kid];
const claims = verify(token, key, { algorithms: ['RS256'] });

JWK and JWKS

A JWK (JSON Web Key) is a public key in JSON form. A JWKS (JWK Set) is a list of them, typically served at a well-known URL so resource servers can fetch current public keys automatically.

{
  'keys': [
    { 'kid': 'key-2024-06', 'kty': 'RSA', 'n': '...', 'e': 'AQAB' }
  ]
}

Spring Security JwtDecoder from JWKS

A Spring resource server can build a decoder straight from a JWKS endpoint, so rotation requires no redeploy of clients.

JwtDecoder decoder = NimbusJwtDecoder
    .withJwkSetUri('https://auth.example.com/.well-known/jwks.json')
    .build();

The Rotation Timeline

A safe rotation follows phases:

  • Publish the new key in the JWKS, but keep signing with the old key
  • Switch signing to the new key
  • Wait for all old tokens to expire
  • Remove the old key

Asymmetric vs Symmetric

Rotation is easier with asymmetric keys (RS256/ES256): you can share public keys freely via JWKS while keeping the private key secret. Symmetric (HS256) requires distributing the shared secret to every verifier.

Storing Private Keys Safely

Never commit signing keys to source control. Store them in a secrets manager (Vault, AWS Secrets Manager, KMS) and load them at runtime. Limit who and what can read them.

Quick Check

Test your understanding of key rotation.

Recap

You learned to rotate JWT signing keys safely:

  • Rotation limits the damage of a leaked key
  • Use kid headers so multiple keys can coexist
  • Publish public keys via a JWKS endpoint
  • Rotate in phases and store private keys in a secrets manager

Asymmetric keys plus JWKS make rotation seamless and downtime-free.

Häufig gestellte Fragen

Ist die Lektion „Signaturschlüssel rotieren und verwalten“ kostenlos?

Ja — der vollständige Text von „Signaturschlüssel rotieren und verwalten“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Spring Security 6 & JWT Authentication-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Spring Security 6 & JWT Authentication-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „Signaturschlüssel rotieren und verwalten“?

Lernen Sie, warum und wie Sie JWT-Signaturschlüssel sicher rotieren – mit Schlüssel-IDs (kid), JWK-Sets und sich überschneidenden Gültigkeitszeiträumen, um Ausfallzeiten zu vermeiden. Du übst Spring Security 6 & JWT Authentication mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um Spring Security 6 & JWT Authentication zu starten?

Keine Vorkenntnisse erforderlich. Spring Security 6 & JWT Authentication auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 4 von 4.

Wie lange dauert die Lektion „Signaturschlüssel rotieren und verwalten“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser Spring Security 6 & JWT Authentication-Lektion Code schreiben und ausführen?

Ja. Jede Spring Security 6 & JWT Authentication-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. Refresh-Token implementieren
  2. Strategien zum Widerrufen von JWTs
  3. Praktiken zur sicheren Token-Speicherung
  4. Signaturschlüssel rotieren und verwalten
← Zurück zu Spring Security 6 & JWT Authentication