Random byte counts describe entropy-bearing bytes, not the final string length. Hex and base64 encode the same bytes at different lengths.
Worked example
import {
createHash,
createHmac,
randomUUID,
randomBytes,
timingSafeEqual,
generateKeyPairSync,
sign,
verify,
createSecretKey,
} from "node:crypto";
console.log(randomBytes(16).length);Result
16Implementation notes
Returning random data as text requires a defined encoding. Consumers should know whether a displayed length is a byte count or a character count.
Try it yourself
Generate 16 bytes and compare both encodings.
Open the Node.js example →Editorial date July 9, 2026 · Published December 6, 2026