I would like to use certificate from a JKS keystore within a NodeJS application.
var fs = require('fs');
var https = require('https');
var options = {
hostname: 'XXX.com',
port: 4443,
path: '/endpoint',
method: 'GET',
key: fs.readFileSync('private.pem'),
cert: fs.readFileSync('public.pem'),
};
var req = https.request(options, function(res) {
res.on('data', function(data) {
process.stdout.write(data);
});
});
req.end();
req.on('error', function(e) {
console.error(e);
});
How can i convert the JKS to PEM ? Thank you
The csr.pem file should be submitted to any valid Certificate Authority like Comodo , Symantec, GoDaddy or other entity that issues digital certificates if you want to buy a SSL certificate. Once you do all the process you should receive a valid certificate. Use that certificate with your Node.js server. Happy coding ❤️!
The Ca Bundle file containing the root and intermediate certificates. ( .ca-bundle extension) Create an HTTPS server in Node.js environment. In the command line, use the following values to create your HTTPS server. For this demonstration, we’ve named it https_server.js, but you can give any name to the server.js file
If you're working with web servers in Node.js you may probably already wanted to create a secure connection, either to provide indeed a secure connection or to allow the access of APIs in the browser that only are accessible if the protocol is HTTPS and not HTTP e.g getUserMedia or webkitSpeechRecognition etc.
In our case, the self-signed client certificate is in the server trust store so that the socket will accept the connection. The server proceeds to read the message using the InputStream. It then uses the OuputStream to echo back the incoming message appending an acknowledgment. 5. Client Java Implementation
How to use JKS certificate for NODE https client request
I don't know if there's a way to do that. But...
How can i convert the JKS to PEM ?
There is definitely a way to do that:
$ keytool -importkeystore -srckeystore keystore.jks -destkeystore keystore.p12
-deststoretype PKCS12 -srcalias <jkskeyalias> -deststorepass <password>
-destkeypass <password>
$ openssl pkcs12 -in keystore.p12 -nokeys -out public.pem
$ openssl pkcs12 -in keystore.p12 -nodes -nocerts -out private.pem
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With