Public
Script
1
2
3
4
5
6
7
8
export async function sha256OfText(text: string) {
// https://stackoverflow.com/a/48161723/712889
const textBuffer = new TextEncoder().encode(text);
// hash the message
const hashBuffer = await crypto.subtle.digest("SHA-256", textBuffer);
const hashArray = Array.from(new Uint8Array(hashBuffer));
return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 23, 2023