Skip to content

Instantly share code, notes, and snippets.

@lalosh
Forked from mikaturunen/calculateHmac.js
Last active May 30, 2022 12:53
Show Gist options
  • Save lalosh/188c158a8c520414035c28b7b167575c to your computer and use it in GitHub Desktop.
Save lalosh/188c158a8c520414035c28b7b167575c to your computer and use it in GitHub Desktop.
Example of calculating hmac in node.js
import * as crypto from 'crypto'
const merchantSecret = 'secret'
const hash = 'sha256'
const encoding = 'base64'
const payload = {
id: 123,
somethingElse: 'not 123'
}
const hmac = crypto
.createHmac(hash, merchantSecret)
.update(Buffer.from(JSON.stringify(payload)).toString(encoding))
.digest('hex')
.toUpperCase()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment