Utiliser un cryptographically sûr pseudorandom nombre generator
CSPRNGs produce sortie indistinguishable de vrai randomness. Apprendre le correct APIs et pourquoi Math.random() est forbidden en sécurité contexts.
- 1
A CSPRNG collects entropy from hardware sources (thermal noise, keystroke timing, disk seek times) and produces output that is computationally indistinguishable from true randomness. In browsers, use crypto.getRandomValues(); in Node.js, use crypto.randomBytes(). Never use Math.random() — it is a PRNG for simulations, not security.
- 2 Générateur d'octets aléatoires →
Générer cryptographically secure random bytes. This tool uses the platform CSPRNG. Specify the number of bytes needed (32 for a 256-bit key, 16 for a 128-bit key, 12 for a GCM nonce).
- 3 Générateur de mots de passe →
Générer a random password using the CSPRNG. Specify length and character set. For high-security passwords, use at least 16 characters with mixed case, digits, and symbols.
- 4
Entropy check: a CSPRNG is only as good as its entropy source. On startup, the OS entropy pool may be low — Node.js and browsers handle this by blocking until enough entropy is collected. On embedded devices or VMs, consider adding hardware entropy sources (e.g., RDRAND, /dev/hwrng).
Questions fréquentes
- Why is Math.random() insecure?
- Math.random() uses a deterministic algorithm (e.g., xorshift) seeded from a predictable value. With enough outputs, an attacker can reconstruct the internal state and predict all future outputs. It is designed for speed in simulations, not unpredictability for security.
- What is entropy?
- Entropy is a measure of unpredictability. A CSPRNG needs high-entropy input (from hardware noise) to produce secure output. On a fresh VM, the entropy pool may be small — use haveged or virtio-rng to supplement it. Low entropy leads to predictable "random" output.