Web Crypto API
The standard Web API for cryptography, such as hashing, HMAC signing and encryption, available in browsers, Node.js and the Edge runtime.
In more detail
It exposes crypto.getRandomValues() and the crypto.subtle object with methods such as sign, verify, digest and encrypt. It is asynchronous and works the same in browsers and server runtimes.
Example
Use crypto.subtle.sign('HMAC', key, data) to sign cookies in Next.js middleware running in the Edge runtime.Related terms
- 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.
- Web APIs — The standard interfaces defined for the web, such as fetch, Request, Response, URL, streams and Web Crypto.
- Edge runtime — A lightweight Next.js runtime based on V8 isolates and standard Web APIs, which starts almost instantly but cannot use most Node.js APIs.
Taught in
- Session Management: Secure Cookies & Token Validation — Next.js 15 & Modern App Router Architecture
- Runtime Environments: Node.js vs Edge Runtime Choice — Next.js 15 & Modern App Router Architecture