JWT Signer & Token Builder

Build, sign, and verify JSON Web Tokens (RFC 7519) using HS256 HMAC secret keys with real-time segment color-coding.

4.9 / 5· 148 verified ratings
•
100% Client-Side Privacy
•
Verified 2026 Engine
Loading tool engine...
Frequently Used With:SHA-256 Hash Generator & Verifier →SHA-512 Hash Generator →JSON Formatter & Validator →JSON Diff & Comparison Tool →
Institutional-Grade Accuracy & Client-Side Privacy Guarantee

Unlike conventional calculator sites that send your financial numbers, payload data, or code snippets across remote web servers, Affi-Chain processes all mathematical derivations, algorithms, and data parsing 100% locally within your browser sandbox. No tracking cookies, no server-side retention, and zero transmission lag.

What is JWT Signing?

JSON Web Token (JWT) Signing is the cryptographic process defined by the IETF RFC 7519 standard that enables two parties to exchange tamper-evident authentication claims and identity metadata. In modern distributed systems, single-page applications (SPAs), mobile clients, and microservice architectures, JWTs serve as the default mechanism for stateless authentication, federated single sign-on (SSO), and OpenID Connect (OIDC) identity assertions.

A signed JWT does not inherently encrypt or conceal payload data; rather, it provides mathematical proof that the payload claims—such as the user's account identifier, organization tenant, granted permissions, and token expiration time—were generated by an authorized issuer and have not been intercepted, modified, or forged in transit. Any unauthorized tampering with even a single bit of the header or payload causes mathematical signature verification to fail immediately.

The Affi-Chain JWT Signer & Verifier provides 100% client-side cryptographic token generation and verification using the browser's hardware-accelerated SubtleCrypto (Web Crypto API). Private secrets never cross the network, guaranteeing total confidentiality during development, debugging, and penetration testing.


The Tripartite Architecture of a Signed JWT

A serialized JSON Web Token is a compact, URL-safe string composed of three distinct segments delimited by period (.) characters:

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c

1. Header (Metadata & Algorithm)

The header contains a JSON object specifying the cryptographic algorithm and token type:

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

This object is encoded using Base64URL (RFC 4648 §5), which strips trailing = padding and substitutes URL-hostile characters (+ → -, / → _).

2. Payload (Claims & Identity Attributes)

The payload contains claims—statements about an entity (typically the authenticated user) and contextual metadata:

  • Registered Claims (RFC 7519 §4.1): Predefined standard keys including:
    • iss (Issuer): Principal issuing the token.
    • sub (Subject): Unique identifier of the user or machine client.
    • aud (Audience): Intended recipient or API endpoint resource.
    • exp (Expiration Time): Unix timestamp marking token expiration.
    • nbf (Not Before): Unix timestamp before which token must be rejected.
    • iat (Issued At): Unix timestamp indicating when token was created.
    • jti (JWT ID): Unique nonce identifier preventing replay attacks.
  • Custom Claims: Application-specific attributes such as roles: ["admin", "billing"] or tenant_id: "org_4810".

Like the header, the payload JSON is serialized to a Base64URL string.

3. Cryptographic Signature

The signature is generated by hashing the concatenated Base64URL header and payload with a cryptographic secret or private key: $$\text{Signature} = \text{HMAC-SHA256}(\text{Base64URL}(\text{Header}) + \text{"."} + \text{Base64URL}(\text{Payload}),\ \text{Secret})$$

The raw signature bytes are then Base64URL-encoded and appended as the final third segment.


Cryptographic Algorithms: Symmetric vs Asymmetric Matrix

Developers choose between symmetric and asymmetric signing algorithms based on architectural trust boundaries:

AlgorithmTypeUnderlying PrimitiveKey StructureIdeal Architecture / Use Case
HS256SymmetricHMAC with SHA-256Single shared secret (minimum 256 bits)Monolithic backends, tightly coupled internal microservices
HS384 / HS512SymmetricHMAC with SHA-384 / SHA-512Single shared secret (384 / 512 bits)High-compliance environments requiring higher bit security
RS256AsymmetricRSA Signature with SHA-2562048+ bit RSA Keypair (Private to sign, Public to verify)Third-party API authorization, OAuth 2.0 Identity Providers (Auth0, Okta)
ES256AsymmetricECDSA with P-256 & SHA-256NIST P-256 Elliptic Curve KeypairMobile apps, IoT devices, microservices requiring small token sizes
EdDSA (Ed25519)AsymmetricEdwards-curve Digital Signature256-bit Curve25519 KeypairCutting-edge cryptography; immune to cache-timing attacks

Practical Code Implementation: In-Browser Web Crypto Signing

Modern web browsers feature the hardware-accelerated window.crypto.subtle API, enabling secure HS256 signing without third-party npm libraries:

/**
 * Signs a JWT payload using HMAC-SHA256 via native browser Web Crypto API.
 * @param {Object} payload - Token claims dictionary.
 * @param {string} secretKey - Plaintext HMAC secret.
 * @returns {Promise<string>} Complete, valid JWT token.
 */
async function signJwtHS256(payload, secretKey) {
  const encoder = new TextEncoder();

  // 1. Construct and encode header & payload
  const header = { alg: "HS256", typ: "JWT" };
  const base64UrlHeader = base64UrlEncode(JSON.stringify(header));
  const base64UrlPayload = base64UrlEncode(JSON.stringify(payload));
  const signingInput = `${base64UrlHeader}.${base64UrlPayload}`;

  // 2. Import secret key into Web Crypto SubtleCrypto key store
  const cryptoKey = await crypto.subtle.importKey(
    "raw",
    encoder.encode(secretKey),
    { name: "HMAC", hash: "SHA-256" },
    false,
    ["sign"]
  );

  // 3. Compute HMAC-SHA256 signature
  const signatureBuffer = await crypto.subtle.sign(
    "HMAC",
    cryptoKey,
    encoder.encode(signingInput)
  );

  // 4. Base64URL encode the raw binary signature
  const base64UrlSignature = arrayBufferToBase64Url(signatureBuffer);

  return `${signingInput}.${base64UrlSignature}`;
}

// Utility: Base64URL string encoder
function base64UrlEncode(str) {
  const base64 = btoa(unescape(encodeURIComponent(str)));
  return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
}

// Utility: ArrayBuffer to Base64URL
function arrayBufferToBase64Url(buffer) {
  const bytes = new Uint8Array(buffer);
  let binary = "";
  for (let i = 0; i < bytes.byteLength; i++) {
    binary += String.fromCharCode(bytes[i]);
  }
  return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
}

// Verification Example:
const testClaims = {
  sub: "usr_9482",
  role: "admin",
  iat: Math.floor(Date.now() / 1000),
  exp: Math.floor(Date.now() / 1000) + 3600 // 1 hour TTL
};

signJwtHS256(testClaims, "super-secret-enterprise-key-32chars!!")
  .then(token => console.log("Generated Signed JWT:\n", token));

Comparison Matrix: JWT vs Alternative Authentication Mechanisms

DimensionJWT (JSON Web Tokens)Traditional Server Sessions (Redis)API KeysPASETO (Platform-Agnostic Security Tokens)
State StorageStateless (stored on client)Stateful (stored in database/memory)Stateful (stored in DB)Stateless or Stateful
Revocation CapabilityDifficult before TTL expires (requires blocklists)Instant (delete session key from Redis)Instant (disable key in DB)Difficult before TTL expires
Payload CapacityModerate (serialized JSON claims)Negligible (stores simple session ID)Zero payload (opaque token)Moderate (strictly typed claims)
Cross-Domain PortabilityOutstanding (CORS / mobile friendly)Requires cookie sharing or proxyingGood (transmitted via headers)Outstanding
Algorithm NegotiationDynamic (alg header - historic risk)Fixed at server levelFixed at server levelStrict, zero algorithm negotiation

Critical Security Vulnerabilities & Implementation Traps

1. The Notorious alg: "none" Vulnerability

Early JWT libraries permitted the header value "alg": "none" to accommodate unsigned debugging tokens. Attackers intercepted valid tokens, modified the payload claims (e.g., role: "user" → role: "admin"), set alg: "none", stripped the signature, and submitted the token. Vulnerable verification routines accepted the payload without validation. Remediation: Explicitly configure verification libraries to accept only whitelisted algorithms (e.g., algorithms: ['HS256']) and reject "none".

2. The Algorithm Confusion / Key-Switching Attack

In hybrid environments transitioning from symmetric to asymmetric keys, an attacker can exploit weak verification implementations:

  1. The server is configured to verify tokens with an RS256 public key.
  2. The attacker re-signs a forged token using HS256, using the server's publicly available RSA public key (PEM format) as the HMAC shared secret.
  3. If the server does not enforce algorithm parity, it verifies the HS256 signature using the public key as a symmetric byte string, successfully validating the forged claims.

3. Weak Secrets and Offline Brute-Forcing

Because JWT signatures are completely stateless and verifiable offline, attackers can capture a valid JWT and run dictionary brute-force tools (like Hashcat or John the Ripper) against the HMAC signature at millions of hashes per second. Remediation: HMAC secrets must be cryptographically random strings of at least 256 bits (32 bytes / 44 Base64 characters). Never use plain dictionary words or company names.

Frequently Asked Questions

What are the three parts of a JWT?
A JWT consists of Header (algorithm & type), Payload (claims and data), and Signature (cryptographic verification stamp), separated by dots.

Explore Related Utilities