Created
November 10, 2015 10:19
-
-
Save rhrn/05be7c9cb968475f7bdb to your computer and use it in GitHub Desktop.
Generate mailgun email signature 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
var crypto = require('crypto'); | |
var mailgunSignature = function(mailgunApiKey) { | |
var token = crypto.randomBytes(25).toString('hex'); | |
var timestamp = Math.floor(Date.now() / 1000); | |
return { | |
token: token, | |
timestamp: timestamp, | |
signature: crypto | |
.createHmac('sha256', mailgunApiKey) | |
.update(new Buffer(timestamp + token, 'utf-8')) | |
.digest('hex') | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment