Skip to content

Web Crypto

How Elide supports the Web Crypto API: getRandomValues, randomUUID, and the digest, key, sign, encrypt and derive algorithms of crypto.subtle.

On this page

The global crypto provides getRandomValues(), randomUUID(), and crypto.subtle from the Web Cryptography API; validation, error names, and messages match Node.

OperationAlgorithms
digestSHA-1, SHA-256, SHA-384, SHA-512, SHA3-256/384/512, cSHAKE128/256 (no function name or customization)
generateKey, importKey, exportKeyRSASSA-PKCS1-v1_5, RSA-PSS, RSA-OAEP, ECDSA, ECDH (P-256, P-384, P-521), Ed25519, X25519, HMAC, AES-CTR/CBC/GCM/KW, ChaCha20-Poly1305; HKDF and PBKDF2 import only
sign, verifyRSASSA-PKCS1-v1_5, RSA-PSS, ECDSA, Ed25519, HMAC
encrypt, decryptRSA-OAEP, AES-CTR, AES-CBC, AES-GCM, ChaCha20-Poly1305
wrapKey, unwrapKeyAES-KW and every encrypt/decrypt algorithm
deriveBits, deriveKeyECDH, X25519, HKDF, PBKDF2
getPublicKey, SubtleCrypto.supportsAs in Node

Key formats: raw (with raw-public and raw-secret aliases), spki, pkcs8, and jwk.

Example

js
// webcrypto.mjs
const data = new TextEncoder().encode("elide");
const digest = await crypto.subtle.digest("SHA-256", data);
console.log(Buffer.from(digest).toString("hex").slice(0, 16));

const key = await crypto.subtle.generateKey({ name: "ECDSA", namedCurve: "P-256" }, false, ["sign", "verify"]);
const signature = await crypto.subtle.sign({ name: "ECDSA", hash: "SHA-256" }, key.privateKey, data);
console.log(signature.byteLength, await crypto.subtle.verify({ name: "ECDSA", hash: "SHA-256" }, key.publicKey, signature, data));

console.log(crypto.randomUUID().length, crypto.getRandomValues(new Uint8Array(4)).length);
utf-8 · js · Lines: 10

elide run webcrypto.mjs prints:

text
bdfdf1cc04d072e4
64 true
36 4
utf-8 · text · Lines: 3

Differences from Node

  • CryptoKey and node:crypto KeyObject share key material: KeyObject.from(cryptoKey) and keyObject.toCryptoKey() convert without copying.
  • Ed448, X448, AES-OCB, KMAC, Argon2, ML-DSA, ML-KEM, TurboSHAKE, and KangarooTwelve reject with NotSupportedError. Use node:crypto generateKeyPair for ML-DSA and ML-KEM keys.

Samples

Reference

Status: Full · Not measured · since 1.1.0

Exports

ExportKindStatusNotes
cryptoobjectFullrandomUUID(), getRandomValues(), subtle
SubtleCryptoclassFulldigest(), encrypt(), decrypt(), sign(), verify(), generateKey(), importKey(), exportKey(), deriveBits(), deriveKey(), wrapKey(), unwrapKey()

Was this page helpful?