Skip to content

Instantly share code, notes, and snippets.

@rm--
Last active November 8, 2021 15:17
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 rm--/c1d9d73d0496fd83f8cc8200ee8b7f0f to your computer and use it in GitHub Desktop.
Save rm--/c1d9d73d0496fd83f8cc8200ee8b7f0f to your computer and use it in GitHub Desktop.
sha512 digest to int
async function digestMessage(message) {
const encoder = new TextEncoder();
const data = encoder.encode(message);
const hash = await crypto.subtle.digest('SHA-512', data);
return hash;
}
digestMessage('input')
.then(digestBuffer => console.log(new DataView(digestBuffer).getUint32()));
3698158640
https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment