Created
January 31, 2021 22:56
-
-
Save DonsWayo/a1e0be1f2b90355bff5fd8dda7c5d438 to your computer and use it in GitHub Desktop.
Dkim generator express
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
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