Implementing the Web Crypto API for Node.js Core

October 20, 2020

The Web Cryptography (or Web Crypto) API is a collection of W3C standardised cryptography primitives defined in the Web Cryptography API specification. It was created after several browsers began adding their own non-interoperable cryptography functions... Read More:

const { subtle } = require('crypto').webcrypto;

// Node.js Web Crypto only supports 128-bit and 256-bit AES keys
async function generateKey(length) {
  return subtle.generateKey(
    { name: 'AES-CBC', length },
    ['encrypt', 'decrypt']);
const { subtle } = require('crypto').webcrypto;

async function generateKeyPair() {
  return subtle.generateKey(
    { name: 'ECDSA', namedCurve: 'P-521' },
    ['sign', 'verify']);