Skip to content

Instantly share code, notes, and snippets.

@rhrn
Created November 10, 2015 10:19
Show Gist options
  • Save rhrn/05be7c9cb968475f7bdb to your computer and use it in GitHub Desktop.
Save rhrn/05be7c9cb968475f7bdb to your computer and use it in GitHub Desktop.
Generate mailgun email signature in node.js
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