selfsigned

Generate self signed certificates private and public keys

Generate a self signed x509 certificate from node.js.

npm install selfsigned
var selfsigned = require('selfsigned');
selfsigned.generate({ subj: '/CN=contoso.com', days: 365 }, function (errresult) {
  console.log('Private Key:', result.privateKey);  
  console.log('Public Key:', result.publicKey);  
});

Will print something like this:

Private Key: -----BEGIN PRIVATE KEY-----
MIIEwAIBADANBgkqhkiG9w0BAQEFAASCBKowggSmAgEAAoIBAQDaj7DZpBhrUxcj
WxI/n3+W8J4hW67kh1WOs1ZjcMmWbRAH/Y79w5YDh+zJ0Y0uUtxWjaVjDRWy9xuH
QRlknLquT0eOxnYT29kXcjsKFBYlDI+6+UL4D/fIDZtXXDfr5IdAWKc/hwZZ9Rxs
L1WpUsGnK6CvKW7cT7hkZzUNdfOIiQLtKUZr11XPNn0m1M1Wsp8c22Hc0iR4BcIk
/KO6+0afxfjQppcRrPe16euZRzCEa25MFS6fcLxk7UpzW9FgZXN4m1ribrMusmWb
m45TQgZoDrliWlz4AS1nm8Ac+NMklW9wNVLCSxaE11j28BrM0LJh2isdJJ2PQU3r
FcNiR3AzAgMBAAECggEBAMBJDrRL1FgIACFQ7FshPiVTiCuc99+C2Vj0mppeDlzT
kvkUsQq9Wmu82CwuumD48XUMpWbhiierk4KJWYfVA8B7a19HZ3bNQs+H5j1Vsq3h
wUokJjEMC1jr77EKJwDYS83msS4I4yOdq+XaNykC7/DdRz8T2r7lPDrJOjmffiSt
lbKEEUuaMhHb4hY8O6mQEsUOVlTvMTJx4+DJp5q8j9g2RQoQyCSsHNx7dbLgCWGf
OaAYlZWVwKsIHScCMeGjiimIxzW8DbjYSEja5xraD3hkFZd+sWMpQb/M4J5N4fM4
tIk5cWbkU6A2PV4ynGmOCVCLHcZLVwqAJ6wrKEzAQWECgYEA7yIZyV1aX0NRlfMK
AyaWgxVZ1+vXKNOxwA/bOk+kTAU/aVMia0puNAzLK26rX0ujj9Z3KK6Y6X6uTQl8
gkDfY6FlBR7BdLK5gnLm1brWEj8CLqE8L3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