const { webcrypto, createHmac } = require('crypto')
async function main() {
const data = 'The quick brown fox jumps over the lazy dog.'
const secret = 'VerySecretKey'
const hmac = createHmac('sha256', secret).update(data).digest().toString('hex')
console.log(hmac)
const hmacSha256 = { name: 'HMAC', hash: 'SHA-256' }
const encoder = new TextEncoder()
const encodedData = encoder.encode(data)
const encodedSecret = encoder.encode(secret)
const secretData = await webcrypto.subtle.importKey('raw', encodedSecret, { name: 'HMAC', hash: 'SHA-256' }, false, ['sign'])
const hmacSubtleBinary = await webcrypto.subtle.sign('HMAC', secretData, encodedData)
const hmacSubtle = Array.from(new Uint8Array(hmacSubtleBinary))
.map(byte => byte.toString(16).padStart(2, '0'))
.join('')
console.log(hmacSubtle)
}
main()
To embed this program on your website, copy the following code and paste it into your website's HTML: