A Cryptographic Password & Secret Generator uses the browser's OS-backed CSPRNG (window.crypto.getRandomValues) with rejection sampling to eliminate modulo bias, measuring brute-force resilience in Shannon entropy bits via H = L * log2(N). Secrets at 80+ bits resist modern offline GPU clusters for centuries, while API keys and HMAC JWT secrets should carry at least 128 to 256 bits of cryptographic entropy.
How to Use Password & Secret Studio
- 1Select Secret Format (Password, Passphrase, API Key, JWT, or Hex)
Choose Password for vault logins, Passphrase for memorable master keys, API Key for prefixed service tokens, or JWT/Hex for 256-bit environment secrets.
- 2Tune Length, Character Sets, or Word Count
Adjust password length (8–64 chars), exclude visually ambiguous characters (0/O, 1/l/I) when needed, or set Diceware word count and separators.
- 3Audit Entropy Bits and Copy Directly Into Your Vault or .env
Verify that Shannon entropy exceeds 80 bits for human passwords or 256 bits for signing secrets, then click Copy to move the generated secret directly from browser RAM.
Core Capabilities & Specifications
- Powered strictly by OS-level window.crypto.getRandomValues() (never Math.random)
- Rejection sampling eliminates statistical modulo bias across all character sets
- 5 modes: Random Password, Diceware Passphrase, API Key, 256-bit Base64URL JWT Secret & Hex Key
- Live Shannon entropy bits (H = L * log2 N) and 100B-guess/sec GPU crack-time rating
- Batch generate 1 to 10 secrets simultaneously with zero network calls or logging
Why Math.random() Is Broken for Security and Rejection Sampling Matters
JavaScript's built-in Math.random() uses a non-cryptographic pseudo-random number generator (typically XorShift128+ in V8). Knowing a handful of consecutive outputs allows an attacker to recover internal PRNG state and predict past and future tokens. Any password, session ID, CSRF token, or API key MUST be sourced from a Cryptographically Secure Pseudo-Random Number Generator (CSPRNG) such as window.crypto.getRandomValues() in browsers or crypto.randomBytes() in Node.js.
Even with a true CSPRNG, mapping a 32-bit random integer to an alphabet of length N via naive rand % N introduces modulo bias whenever N does not evenly divide 2^32. Rejection sampling discards values at or above Math.floor(2^32 / N) * N, ensuring every character or wordlist entry is chosen with exact uniform probability 1/N.
- Never use Math.random() for passwords, OTPs, reset tokens, or API keys.
- Rejection sampling guarantees strict mathematical uniformity across non-power-of-two alphabets.
- 256 bits of entropy (32 random bytes) provides ~1.15 x 10^77 possibilities—safe against classical and Grover-halved quantum brute force.
export function unbiasedRandomInt(maxExclusive: number): number {
const range = 0x100000000; // 2^32
const limit = range - (range % maxExclusive);
const buf = new Uint32Array(1);
let value = 0;
do {
crypto.getRandomValues(buf);
value = buf[0];
} while (value >= limit);
return value % maxExclusive;
}
export function generateJwtSecret256(): string {
const bytes = new Uint8Array(32);
crypto.getRandomValues(bytes);
return Buffer.from(bytes).toString("base64url");
}Shannon Entropy Math vs Offline GPU Cracking Speeds
Password resilience against brute-force guessing is measured in bits of entropy: H = L * log2(N), where L is the secret length (characters or dictionary words) and N is the uniform pool size. Adding a single extra character multiplies search space exponentially, which is why length beats complex short substitutions (like P@ssw0rd1) every time.
Modern multi-GPU cracking rigs running Hashcat can evaluate upwards of 100 billion fast-hash guesses (MD5/SHA-1/unsalted SHA-256) per second. A 50-bit password falls in hours against fast hashes, whereas a 16-character mixed password (~100 bits) or a 6-word Diceware passphrase requires astronomically longer than the age of the universe—especially when servers store hashes using memory-hard KDFs like Argon2id.
- User vault passwords: aim for >= 16 random characters (~95–105 bits).
- Human-typed master passphrases: aim for 5–7 uniformly sampled random words plus separator/digit.
- API keys & JWT HS256 secrets: always use >= 256 bits (32 raw CSPRNG bytes in Base64URL or Hex).
Prefix Conventions for Leaked-Secret Scanning (GitHub & TruffleHog)
Modern developer platforms prepend recognizable static prefixes to API tokens (for example, Stripe's sk_live_, GitHub's ghp_, or custom prefixes like fs_live_). Prefixes do not reduce entropy as long as the random suffix carries >= 192–256 bits of CSPRNG randomness, and they unlock automated secret scanning across Git repositories, CI logs, and Slack messages so accidentally committed keys can be revoked within seconds.
import { createHash, timingSafeEqual } from "node:crypto";
export function hashApiKey(rawKey: string): string {
// Store only SHA-256 digest in DB; show rawKey to user exactly once
return createHash("sha256").update(rawKey, "utf8").digest("hex");
}
export function verifyApiKey(rawKey: string, storedHexHash: string): boolean {
const candidate = Buffer.from(hashApiKey(rawKey), "hex");
const expected = Buffer.from(storedHexHash, "hex");
return candidate.length === expected.length && timingSafeEqual(candidate, expected);
}Engineering Comparison Matrix
| Secret Type | Entropy Formula | Typical Entropy | Recommended Use Case |
|---|---|---|---|
| 12-char Mixed Password | 12 * log2(90) | ~78 bits | Low-risk legacy forms with short max length |
| 20-char Full Charset Password | 20 * log2(90) | ~130 bits | Password manager accounts, cloud consoles |
| 5-Word Random Passphrase | 5 * log2(W) + digit | ~45 – 70 bits | Human-typed master unlock (use 6–8 words for full Diceware) |
| Prefixed API Key (32 Base62) | 32 * log2(62) | ~190 bits | Backend bearer API keys & webhook tokens |
| 256-bit Base64URL / Hex Key | 32 bytes * 8 | 256 bits | JWT HS256/HS512 signing, AES-256-GCM, NEXTAUTH_SECRET |
Common Production Pitfalls to Avoid
- •Using online password generators that fetch passwords from a server API instead of generating them via local WebCrypto.
- •Generating HS256 JWT signing keys from short English phrases instead of a full 256-bit CSPRNG secret.
- •Storing user-issued API keys in plaintext inside databases instead of storing a SHA-256 hash and displaying the raw token once.
- •Reusing the same secret key across staging and production environments.
Frequently Asked Questions
Are generated passwords or JWT secrets ever sent over the network?
Never. Every secret is generated strictly inside your browser's local RAM via window.crypto.getRandomValues() with zero network requests, telemetry, or localStorage persistence.
Why is a 256-bit Base64URL secret recommended for JWT HS256 and NEXTAUTH_SECRET?
RFC 7518 requires HMAC-SHA256 keys to be at least 256 bits (32 random bytes) long to match the cryptographic security level of SHA-256. Base64URL encoding represents those 32 bytes cleanly in 43 URL- and .env-safe characters without padding issues.
Should I exclude ambiguous characters like 0, O, 1, l, and I?
Yes when passwords may be typed manually on a mobile phone, server KVM terminal, or printed recovery sheet. Excluding 7 ambiguous glyphs barely changes entropy (~0.1 bits per character) while dramatically cutting transcription errors.
What makes a Diceware passphrase secure compared to a human-invented phrase?
Humans pick predictable quotes, song lyrics, and grammar patterns that attackers crack quickly with Markov models. Uniformly sampling random dictionary words via CSPRNG removes linguistic predictability so each word adds true independent entropy.
How fast can attackers crack passwords offline if a database leaks?
If a site hashed passwords with fast algorithms (MD5/SHA-256), modern GPU clusters can test ~100 billion guesses per second. With Argon2id or bcrypt, guessing drops by orders of magnitude—yet keeping generated secrets above 100 bits guarantees safety regardless of the server's hash function.