Last active
October 26, 2022 05:30
-
-
Save JenniferFuBook/60c950a291065a4ec22c916101622ca0 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
const { subtle } = globalThis.crypto; | |
(async function() { | |
const key = await subtle.generateKey({ | |
name: 'HMAC', | |
hash: 'SHA-256', | |
length: 256 | |
}, true, ['sign', 'verify']); | |
console.log('key =', key); | |
const enc = new TextEncoder(); | |
const message = enc.encode('I love cupcakes'); | |
console.log('message =', message); | |
const digest = await subtle.sign({ | |
name: 'HMAC' | |
}, key, message); | |
console.log('digest =', digest); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment