Skip to content

Instantly share code, notes, and snippets.

@JenniferFuBook
Last active October 26, 2022 05:30
Show Gist options
  • Save JenniferFuBook/60c950a291065a4ec22c916101622ca0 to your computer and use it in GitHub Desktop.
Save JenniferFuBook/60c950a291065a4ec22c916101622ca0 to your computer and use it in GitHub Desktop.
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