Web Crypto API

Random values, UUIDs, and cryptographic digests

The global crypto object provides:

MemberSupport
getRandomValues(typedArray)Cryptographically strong random bytes.
randomUUID()A random version-4 UUID.
subtle.digest()SHA-1, SHA-256, SHA-384, and SHA-512.
const bytes = new Uint8Array(16);
crypto.getRandomValues(bytes);

const digest = await crypto.subtle.digest(
  "SHA-256",
  new TextEncoder().encode("hello"),
);
digest.byteLength; // 32

Other SubtleCrypto operations, including encryption, signing, key generation/import/export, derivation, and wrapping, reject with a NotSupportedError DOMException.

For the Node API, see node:crypto.