Skip to content

Instantly share code, notes, and snippets.

@remarkablemark
Created August 30, 2021 01:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save remarkablemark/92aa346b7bca97d6f108ad2c67c2e368 to your computer and use it in GitHub Desktop.
Save remarkablemark/92aa346b7bca97d6f108ad2c67c2e368 to your computer and use it in GitHub Desktop.
async function hash(string) {
const utf8 = new TextEncoder().encode(string);
const hashBuffer = await crypto.subtle.digest('SHA-256', utf8);
const hashArray = Array.from(new Uint8Array(hashBuffer));
const hashHex = hashArray
.map((bytes) => bytes.toString(16).padStart(2, '0'))
.join('');
return hashHex;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment