128-Character Base64 JWT Secret Generator

A 128-character Base64 secret is the standard shape for a JWT signing key in JavaScript and TypeScript backends. Because Base64 packs 6 bits into every character, this generator draws 96 raw random bytes from the Web Crypto API and encodes them URL-safely before trimming to exactly 128 characters. At 128 characters it supplies roughly 768 bits of entropy, positioning it in the "generous" tier for HMAC-based JWT signing (HS384 / HS512).

0 chars·Weak(0 bits)
Generating…

Why 128 characters?

128 characters is a deliberately generous size: teams pick it when the secret must survive years of rotation policy without ever being the weakest link in the auth chain, and when HS512 is in play.

Entropy
A–Z, a–z, 0–9, -, _ (64-symbol alphabet, padding stripped) → ~6 bits/char × 128 chars ≈ 768 bits
Algorithm fit
HS384 / HS512 — Comfortably covers HS512's 512-bit output while remaining short enough to paste into most secret managers without truncation issues.

Storage & performance: Exceeds the 64-byte SHA-256 block size, which means HMAC first hashes the key down to 32 bytes before use — a one-time, sub-microsecond cost that's irrelevant outside extremely hot signing loops.

Most JWT libraries accept the Base64 string as-is and treat it as a UTF-8/ASCII byte sequence — no decoding step is required before signing.

When to use / when to avoid

Use a 128-char Base64 secret when…

  • You're signing tokens with HS512 and want a key sized to match its output.
  • Compliance or a security audit calls for 'at least 1024 bits' of key material.
  • The secret is long-lived (multi-year rotation window) and needs extra margin.

Consider a different length when…

  • Overkill for a quick local prototype where a 32-char secret would do.
  • Unnecessary if your platform truncates env vars below this length.

Generate a 128-char Base64 secret in code

Each snippet below produces the same shape of secret as the tool above: a 128-character base64 string using each language's cryptographically secure RNG.

Node.js
import crypto from "node:crypto";
const secret = crypto.randomBytes(96)
  .toString("base64url")
  .slice(0, 128);
console.log(secret); // 128 chars, URL-safe base64
Python
import base64, os
raw = os.urandom(96)
secret = base64.urlsafe_b64encode(raw).decode().rstrip("=")[:128]
print(secret)  # 128-char base64url secret
Go
package main

import (
	"crypto/rand"
	"encoding/base64"
	"fmt"
)

func main() {
	raw := make([]byte, 96)
	rand.Read(raw)
	secret := base64.RawURLEncoding.EncodeToString(raw)[:128]
	fmt.Println(secret) // 128-char base64url secret
}
Java
import java.security.SecureRandom;
import java.util.Base64;

byte[] raw = new byte[96];
new SecureRandom().nextBytes(raw);
String secret = Base64.getUrlEncoder().withoutPadding()
    .encodeToString(raw).substring(0, 128);
System.out.println(secret); // 128-char base64url secret

Security notes

  • Generated locally with crypto.getRandomValues — nothing is sent to a server, logged, or cached.
  • Regenerate before first use in production; treat any secret shown on shared screens as compromised.
  • Store it in a secrets manager or git-ignored .env file, never in source control or client-side code.
  • Rotate on a schedule and support at least one overlapping "next" secret to allow zero-downtime rotation.

FAQ

Why does this generator produce 128-character Base64 strings specifically?

128 characters is a deliberately generous size: teams pick it when the secret must survive years of rotation policy without ever being the weakest link in the auth chain, and when HS512 is in play. The exact length is fixed at 128 so the output is deterministic to copy into configuration without manual trimming.

How many bits of entropy does a 128-character Base64 secret carry?

A–Z, a–z, 0–9, -, _ (64-symbol alphabet, padding stripped) yields about 6 bits per character, so 128 characters work out to roughly 768 bits of entropy — well above the 256-bit floor commonly cited for HMAC-SHA256 keys.

Which JWT algorithm should I pair with a 128-char Base64 secret?

HS384 / HS512. Comfortably covers HS512's 512-bit output while remaining short enough to paste into most secret managers without truncation issues.

Base64 vs. other formats at 128 characters — which should I pick?

URL-safe Base64 encoding is the most common format for HS256/HS384/HS512 JWT signing keys stored in environment variables. Most JWT libraries accept the Base64 string as-is and treat it as a UTF-8/ASCII byte sequence — no decoding step is required before signing. Pick a different format only if your framework or secrets manager has a stated preference.

Does the 128-character length affect signing or verification performance?

Exceeds the 64-byte SHA-256 block size, which means HMAC first hashes the key down to 32 bytes before use — a one-time, sub-microsecond cost that's irrelevant outside extremely hot signing loops.

Where should I store a 128-character Base64 JWT secret?

Use a secrets manager (Doppler, AWS Secrets Manager, GCP Secret Manager, HashiCorp Vault, 1Password) or a git-ignored .env file. Never commit it to source control, and rotate it on a schedule appropriate for HS384 / HS512.

Is this 128-char Base64 secret generated securely?

Yes — it's produced entirely in your browser with the Web Crypto API's crypto.getRandomValues, a cryptographically secure PRNG. No network request is made and the value is never transmitted or logged.

Can I reuse this Base64 secret for something other than JWTs?

Yes. A 128-character Base64 string is a general-purpose high-entropy secret — it also works as an API key, session-encryption key, or CSRF token secret needing around 768 bits of randomness.

Related generators & tools

Recent articles

Guides on JWT secrets, signing algorithms, and token security.

Browse all articles →