node:crypto
The built-in Node.js module for hashing, HMACs, encryption, random numbers and key derivation, backed by OpenSSL.
In more detail
Import it with import { createHash } from "node:crypto". Slow functions such as pbkdf2 and scrypt have asynchronous versions that run on libuv's thread pool, and Sync versions that block the main thread.
Related terms
- cryptography — The mathematics and techniques used to keep data secret, prove it has not been changed and prove who sent it.
- OpenSSL — A widely used toolkit and library for cryptography and TLS, including the openssl command-line tool.
- createHash() — The node:crypto function that creates a hash object: feed it data with update() and get the result with digest().
- HMAC — A way of combining a secret key with a hash function to produce a tag that shows a message came from someone holding the key and was not changed.
- PBKDF2 — A standard way to turn a password into an encryption key, or a stored password hash, by hashing it many thousands of times so guessing is slow.
Taught in
- libuv Architecture: Event Demultiplexer & Thread Pool — Node.js Internals & Backend Services
- Cryptographic Primitives: node:crypto & Ciphers — Node.js Internals & Backend Services
- Native WebSockets: Bidirectional Real-Time Streams — Node.js Internals & Backend Services