Skip to content
BetterPass logo

Secure Opaque Token Generator

Generate high-entropy tokens for sessions and API keys — batch mode, standard Base64, prefix/suffix, and copy as a Bearer header.

Result
8–256 characters
1–100 · 1 = single token
Optional · max 32 chars
Optional · max 32 chars
Random core entropy: 192 bits per token (32 chars × 64-char alphabet). A prefix or suffix only labels the token — it adds no randomness.
Tokens are random and opaque; you can store related data on your server keyed by this token. Delete the server-side record to revoke instantly.

What is Opaque Token Generator?

An opaque token is a random string your server uses as a pointer: every request presents it, and the server looks it up in its own store. There is no payload to read, no signature to verify, and nothing sensitive sits on the client — the token stops working the moment its server-side record is deleted.

The generator adds the conveniences you usually bolt on yourself:

Standard Base64 alphabet — RFC 4648 Base64 (A–Z a–z 0–9 + /) alongside the URL-safe, Base62, hex, and extended sets.
Batch generation with export — create up to 100 tokens at once and export them as TXT, CSV, or JSON.
Prefix / suffix customization — tag tokens like sk_live_ or _prod for environment and key-type scoping.
Copy as Bearer header — copy any token ready to paste as Authorization: Bearer <token>.
Revocable by design — the server-side record is the source of truth; deleting it invalidates the token immediately.

Zero-Server Tool Data Guarantee

All tokens are generated locally in your browser using the Web Crypto API (crypto.getRandomValues). No token data ever leaves your device — generated tokens, prefixes, and suffixes are never transmitted to any server.

How to Use

01

Set Length and Alphabet

Choose a random-core length (8–256) and an alphabet — URL-safe, standard Base64, Base62, hex, or extended URL-safe.

02

Configure Batch and Shape

Set the count (1–100) for single or batch output, and add an optional prefix or suffix to scope the tokens.

03

Generate

Click 'Generate' to create cryptographically secure random tokens using crypto.getRandomValues().

04

Copy or Export

Copy any token, copy it as an 'Authorization: Bearer <token>' header, or export the whole batch as TXT, CSV, or JSON.

Common Use Cases

Session Identifiers

Generate secure session tokens for httpOnly cookies. Your server maps the token to a user session in Redis or a database.

API Key Provisioning

Batch-generate keys for teams or integrations, scope them with prefixes like sk_live_, and export the set as CSV or JSON for your records.

OAuth 2.0 Bearer Tokens

Issue opaque bearer tokens and validate them with an Authorization header. Revoke instantly by deleting the server-side record.

Password Reset Tokens

Generate one-time-use tokens for password reset flows. The token is stored server-side with a short expiration window.

Environment Scoping

Use prefix/suffix markers to distinguish production, staging, and sandbox keys without decoding the token.

Implementation Examples

JavaScriptBrowser — batch + prefix (Web Crypto)
// Generate N URL-safe tokens with an optional prefix/suffix
const ALPHABET_URL = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
const ALPHABET_B64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
function randomByte() {
return crypto.getRandomValues(new Uint8Array(1))[0];
}
function randomToken(length, alphabet = ALPHABET_URL) {
const size = alphabet.length;
const limit = 256 - (256 % size); // reject bytes that would bias the output
let out = "";
for (let i = 0; i < length; i++) {
let b;
do { b = randomByte(); } while (b >= limit);
out += alphabet[b % size];
}
return out;
}
function generateBatch(count, length, { prefix = "", suffix = "", alphabet = ALPHABET_URL } = {}) {
return Array.from({ length: count }, () => prefix + randomToken(length, alphabet) + suffix);
}
const tokens = generateBatch(10, 32, { prefix: "sk_live_" });
// tokens: ["sk_live_a3f8c1e2b4d6...", "sk_live_9b0c…", ...]
// Send the first token as a Bearer header
fetch("/api/me", { headers: { Authorization: "Bearer " + tokens[0] } });

Opaque Tokens vs JWTs

FeatureOpaque TokenJWT
Contains user dataNo (lookup key only)Yes (claims payload)
ValidationDatabase / cache lookupCryptographic signature
RevocationInstant (delete record)Difficult until expiration
Token sizeFixed (e.g., 32 bytes)Grows with claims
Server-side storageRequiredOptional (stateless)
Best forSessions, API keysStateless auth, microservices

Production Best Practices & Security

Use at least 32 random characters — shorter tokens are easier to brute-force; 32 URL-safe characters give ~192 bits of entropy. Why:an attacker can enumerate a small token space with repeated requests; ~192 bits makes brute-force attacks practically impossible.
Use standard Base64 only when you control storage and transport — the + and / characters (and = when padded) require URL-encoding in query strings and paths. Why:a + is decoded as a space in form-encoded URLs and a bare / can break path parsing, so these tokens get mangled in transit; URL-safe alphabets avoid that class of bug entirely.
Treat prefix/suffix as metadata, not entropy — a guessable prefix like sk_live_ does not strengthen the token. Why:only the random core contributes security; keep the core at least 32 characters even when you add a prefix.
Store only a hash of the token server-side — e.g. SHA-256 — so a database leak does not expose usable tokens. Why:a hashed token is useless to an attacker even if the entire store is dumped, while you can still look up sessions by hashing each presented token.
Rotate tokens on privilege change — issue a new token when a user's role or permissions change to prevent stale access. Why:a token issued before a privilege change still maps to the old permissions in your server-side store; rotation forces re-validation.
Generate with crypto.getRandomValues — never Math.random(). Why:Math.random() uses a predictable PRNG an attacker can reproduce; the Web Crypto API draws on hardware-backed CSPRNG entropy.

Frequently Asked Questions

An opaque token is a randomly generated string your server uses as a pointer: every request presents it, and the server looks it up in its own database or cache. The token is meaningless everywhere else.

Where a JWT carries claims inside itself, an opaque token carries none — who the user is and what they may do lives server-side, keyed by the value.

That is exactly why revocation is so clean: remove the record and the token stops working on the very next request. It is the standard choice for session cookies and OAuth 2.0 bearer tokens.