Back to project
Salt

Random Salt Generation

The salt comes from the browser's secure random number generator, then gets converted into hexadecimal so it can be displayed on the page.

function randHex(bytes) {
  const arr = new Uint8Array(bytes);
  crypto.getRandomValues(arr);

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

async function genSalt() {
  currentSalt = randHex(32);
  await updateSalted();
}