JWT Decoder & ValidatorSpecialized Version
🎟️

JWT Header Decoder

Decode header

JWT Header Decoder

Decode the JWT header to view the signing algorithm and token type. The header determines how the token signature is verified.

JWT Header Structure

The header is the first part of the JWT (before the first dot) and contains metadata about the token:

``json { "alg": "HS256", "typ": "JWT" } `

Header Fields

FieldDescriptionCommon Values
algSigning algorithmHS256, RS256, ES256
typToken typeJWT
kidKey IDUsed for key rotation
jkuJWK Set URLURL to public keys
x5uX.509 URLURL to certificate
x5cX.509 CertificateCertificate chain

JWT Header Decoder

`javascript function decodeJWTHeader(token) { const headerPart = token.split('.')[0];

// Base64URL decode const base64 = headerPart.replace(/-/g, '+').replace(/_/g, '/'); const padded = base64 + '=='.slice(0, (4 - base64.length % 4) % 4); const decoded = atob(padded);

const header = JSON.parse(decoded);

// Analyze algorithm security const algorithmInfo = getAlgorithmInfo(header.alg);

return { raw: headerPart, decoded: header, algorithm: algorithmInfo }; }

function getAlgorithmInfo(alg) { const algorithms = { 'HS256': { type: 'HMAC', hash: 'SHA-256', keyType: 'symmetric', secure: true }, 'HS384': { type: 'HMAC', hash: 'SHA-384', keyType: 'symmetric', secure: true }, 'HS512': { type: 'HMAC', hash: 'SHA-512', keyType: 'symmetric', secure: true }, 'RS256': { type: 'RSA', hash: 'SHA-256', keyType: 'asymmetric', secure: true }, 'RS384': { type: 'RSA', hash: 'SHA-384', keyType: 'asymmetric', secure: true }, 'RS512': { type: 'RSA', hash: 'SHA-512', keyType: 'asymmetric', secure: true }, 'ES256': { type: 'ECDSA', curve: 'P-256', keyType: 'asymmetric', secure: true }, 'ES384': { type: 'ECDSA', curve: 'P-384', keyType: 'asymmetric', secure: true }, 'ES512': { type: 'ECDSA', curve: 'P-521', keyType: 'asymmetric', secure: true }, 'PS256': { type: 'RSA-PSS', hash: 'SHA-256', keyType: 'asymmetric', secure: true }, 'none': { type: 'None', keyType: 'none', secure: false, warning: 'INSECURE!' } };

return algorithms[alg] || { type: 'Unknown', secure: false }; } ``

Algorithm Comparison

AlgorithmTypeBest For
HS256SymmetricSingle server, simple setup
RS256AsymmetricMicroservices, public verification
ES256Elliptic CurveMobile, smaller tokens

Frequently Asked Questions

What does the JWT algorithm (alg) field mean?

The alg field specifies how the token signature is created and verified. HS256 uses a shared secret (HMAC-SHA256)—both parties need the secret. RS256 uses RSA keys (asymmetric)—sign with private key, verify with public key. The algorithm must match between token creation and verification.

Should I use HS256 or RS256?

HS256 is simpler—one secret key for signing and verification. Use when token creator and validator are the same service. RS256 uses public/private keys—sign with private, verify with public. Use when third parties need to verify tokens without accessing signing capability.

What is the kid (Key ID) header?

kid identifies which key was used to sign the token. Essential for key rotation—you can have multiple active keys and specify which one signed each token. Validators look up the correct key using the kid. Without it, you must try all keys or can only use one key at a time.

Related Tools

Explore other tools you might find useful:

Related Calculators