How to use JKS certificate for NODE https client request

*爱你&永不变心* 提交于 2019-12-07 09:21:07

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/50656756/how-to-use-jks-certificate-for-node-https-client-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!