Skip to content

Instantly share code, notes, and snippets.

@danielearwicker
Created October 26, 2022 16:16
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 danielearwicker/e54432a46e51307d947390a396c2b92f to your computer and use it in GitHub Desktop.
Save danielearwicker/e54432a46e51307d947390a396c2b92f to your computer and use it in GitHub Desktop.
Getting base64 string of SHA-256 from some string input, natively in modern browsers
const message = "Hello, this is the message";
const hash = new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(message)));
const base64 = btoa(String.fromCharCode(...hash)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment