Skip to content

Instantly share code, notes, and snippets.

@praisedare
Forked from remarkablemark/browser-hash.js
Created November 18, 2023 16:07
Show Gist options
  • Save praisedare/64e523d3dcf538addb7e873565b04eeb to your computer and use it in GitHub Desktop.
Save praisedare/64e523d3dcf538addb7e873565b04eeb to your computer and use it in GitHub Desktop.
function hash(string) {
const utf8 = new TextEncoder().encode(string);
return crypto.subtle.digest('SHA-256', utf8).then((hashBuffer) => {
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