crypto.randomBytes()
A node:crypto function that returns bytes from a cryptographically secure random number generator, suitable for keys, IVs and tokens.
In more detail
Never use Math.random() for security values: it is predictable. crypto.randomUUID() is a convenient choice for random identifiers.
Related terms
- secret key — A value known only to the parties allowed to use it, needed to create or check an HMAC or to encrypt and decrypt data.
- initialization vector — A random or unique value fed into encryption with the key, so the same plaintext encrypts differently each time.
Taught in
- Cryptographic Primitives: node:crypto & Ciphers — Node.js Internals & Backend Services