Skip to content

Instantly share code, notes, and snippets.

@DonsWayo
Created January 31, 2021 22:56
Show Gist options
  • Save DonsWayo/a1e0be1f2b90355bff5fd8dda7c5d438 to your computer and use it in GitHub Desktop.
Save DonsWayo/a1e0be1f2b90355bff5fd8dda7c5d438 to your computer and use it in GitHub Desktop.
Dkim generator express
const NodeRsa = require('node-rsa');
function generateDkim (bits, domain, selector) {
var key = new NodeRsa({b: bits});
var privateKey = key.exportKey('pkcs8-private-pem');
var publicKey = key.exportKey('pkcs8-public-pem');
const dns =
selector +
'._domainkey.' +
domain +
" IN TXT " +
"( v=DKIM1; p=" + public_key.replace('-----BEGIN PUBLIC KEY-----', '').replace('-----END PUBLIC KEY-----', '').replace(/\s/g, '') + " )";
return {"privateKey": privateKey, "publicKey": publicKey, "dns": dns}
};
app.post('/dkim', (req, res) => {
const bits = req.body.bits || 2048;
const domain = req.body.domain;
const selector = 'default';
return generateDkim(bits, domain, selector)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment