-
-
Save lalosh/188c158a8c520414035c28b7b167575c to your computer and use it in GitHub Desktop.
Example of calculating hmac in node.js
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
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