Skip to content

Instantly share code, notes, and snippets.

@waghcwb
Created September 24, 2019 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waghcwb/1b21da6c0e86784c4cd04ec69c5a65c7 to your computer and use it in GitHub Desktop.
Save waghcwb/1b21da6c0e86784c4cd04ec69c5a65c7 to your computer and use it in GitHub Desktop.
const sha256 = async message => {
const msgBuffer = new TextEncoder('utf-8').encode(message);
const hashBuffer = await crypto.subtle.digest('SHA-256', msgBuffer);
const hashArray = Array.from(new Uint8Array(hashBuffer));
return hashArray.map(b => ('00' + b.toString(16)).slice(-2)).join('');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment