不喜欢广告? 无广告 今天

Cryptographic Nonce Generator

开发人员
广告 · 消除?

Usage Examples

What is a Nonce?

广告 · 消除?

指导

Cryptographic Nonce Generator

Cryptographic Nonce Generator

Generate cryptographically secure nonces (numbers used once) for CSP headers, OAuth state parameters, CSRF tokens, session IDs, and more. Uses crypto.getRandomValues() for true randomness — no Math.random() fallback. Output in hex, Base64, Base64url, or decimal array format. Everything runs in your browser; nothing is sent to any server.

如何使用

Select a byte length (8, 16, 24, 32, or 64 bytes, or enter a custom length), choose your output format (hex, Base64, Base64url, or decimal array), and set how many nonces to generate. Values generate automatically as you change settings. Copy individual nonces or use the pre-formatted usage examples that auto-populate with your generated nonce for CSP headers, HTML script tags, OAuth state parameters, CSRF tokens, and session cookies.

特征

  • Cryptographic Randomness — Uses crypto.getRandomValues() exclusively. No Math.random() fallback. Produces cryptographically secure random bytes from the OS entropy source.
  • 多种输出格式 — Hex (lowercase), Base64 (standard), Base64url (URL-safe, no padding), and decimal byte array. Each format suited for different use cases.
  • Configurable Byte Length — Preset lengths (8, 16, 24, 32, 64 bytes) or custom. Entropy display shows bits of randomness (bytes × 8).
  • 批量生成 — Generate up to 100 nonces at once, each with individual copy button.
  • Usage Examples — Pre-formatted code snippets auto-populated with your nonce: CSP header, HTML script nonce attribute, OAuth state parameter, CSRF hidden input, and session cookie.
  • Entropy Display — Shows bits of entropy for the configured byte length so you can verify your nonce meets security requirements.
  • 100% 客户端 — Nothing leaves your browser. No server requests, no logging. Your nonces stay private.

What is a Nonce?

A nonce (“number used once”) is a random value that should only be used a single time. In cryptography and web security, nonces prevent replay attacks, cross-site scripting (XSS), and request forgery. The key requirement is unpredictability — an attacker must not be able to guess the nonce value, which is why cryptographic randomness (not pseudo-random) is essential.

广告 · 消除?

What is the difference between a nonce and a random token?

A nonce is specifically a “number used once” — it must be unique for each use and should never be reused. A random token is a broader term for any random value used for authentication or identification. In practice, cryptographic nonces are random tokens with the additional constraint of single use. CSP nonces must be regenerated on every page load. OAuth state parameters must be unique per authorization request. CSRF tokens should be unique per session or per request. The generation method is the same (cryptographic randomness), but the usage pattern differs.

Why not use Math.random() for nonces?

Math.random() uses a pseudo-random number generator (PRNG) that is NOT cryptographically secure. Its output is deterministic — if an attacker knows the internal state, they can predict future values. Modern browsers use xorshift128+ or similar algorithms for Math.random(), which are fast but predictable. crypto.getRandomValues() uses the operating system’s cryptographic random number generator (CSPRNG), which draws entropy from hardware events, making its output unpredictable even to an attacker who knows the algorithm. For any security-sensitive value, always use crypto.getRandomValues().

How many bytes should my nonce be?

It depends on the use case. For CSP nonces, 16 bytes (128 bits) is the recommended minimum — sufficient to prevent brute-force guessing. For OAuth state parameters, 16-32 bytes is standard. For CSRF tokens, 16 bytes minimum. For session IDs, 32 bytes (256 bits) provides a very comfortable security margin. The general rule: 128 bits (16 bytes) of entropy is considered computationally infeasible to brute-force with current technology. 256 bits provides security against theoretical quantum computing attacks.

What is Base64url and when should I use it?

Base64url is a URL-safe variant of Base64 encoding. Standard Base64 uses + and / characters, which have special meaning in URLs and can cause issues in query parameters, cookies, and file names. Base64url replaces + with – and / with _, and omits the = padding. Use Base64url for OAuth state parameters, URL query values, JWT tokens, cookie values, and any context where the nonce will appear in a URL or HTTP header. Use standard Base64 for CSP nonces (the spec expects standard Base64) and contexts where URL safety isn’t a concern.

想要享受无广告的体验吗? 立即无广告

安装我们的扩展

将 IO 工具添加到您最喜欢的浏览器,以便即时访问和更快地搜索

添加 Chrome 扩展程序 添加 边缘延伸 添加 Firefox 扩展 添加 Opera 扩展

记分板已到达!

记分板 是一种有趣的跟踪您游戏的方式,所有数据都存储在您的浏览器中。更多功能即将推出!

广告 · 消除?
广告 · 消除?
广告 · 消除?

新闻角 包含技术亮点

参与其中

帮助我们继续提供有价值的免费工具

给我买杯咖啡
广告 · 消除?