Last active
July 6, 2024 02:13
-
-
Save ewalk153/9127b47f02a6baf0aecb2012428daa76 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(async (secret, body) => { | |
let enc = new TextEncoder("utf-8"); | |
let algorithm = { name: "HMAC", hash: "SHA-256" }; | |
let key = await crypto.subtle.importKey("raw", enc.encode(secret), algorithm, false, ["sign", "verify"]); | |
let signature = await crypto.subtle.sign(algorithm.name, key, enc.encode(body)); | |
let hexString = Array.from(new Uint8Array(signature)).map(byte => byte.toString(16).padStart(2, '0')).join(''); | |
console.log(hexString); | |
})("my secret and secure key", "input message"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment