Back to project
Web Crypto API

Browser-Side Hashing

The demo uses the browser's built-in cryptography API for the SHA digests instead of sending data anywhere else.

async function sha(algo, msg) {
  const buffer = await crypto.subtle.digest(
    algo,
    new TextEncoder().encode(msg)
  );

  return Array.from(new Uint8Array(buffer))
    .map((b) => b.toString(16).padStart(2, '0'))
    .join('');
}

const hash = await sha('SHA-256', value);