NodeJS:以 DER 格式验证证书
我正在使用 crypto
模块来验证证书,但我的证书和公钥都是 DER 格式.crypto
模块似乎不接受这种格式.
I'm using crypto
module to validate a certificate, but both, my certificate and my public key are in DER format. It seems that crypto
module does not accept this format.
有没有办法(或模块)使用 NodeJS 将 DER 转换为 PEM 格式?我找不到任何东西,也无法使用命令行通过 shell 调用 openssl.
Is there a way (or module) to convert DER to PEM format using NodeJS? I couldn't find any and cannot use command line to call openssl via shell.
更新:这与 HTTPS 证书无关.这是关于一般的 X.509 证书.如果您将问题标记为否定,请发表评论以证明其合理性.帮不上忙也别傻了.
UPDATE: It's not about HTTPS certificates. It's about general X.509 certificates. And if you mark the question as negative, please leave a comment to justify it. Don't be a stupid if you are not able to help.
推荐答案
Dominykas 的回答很好,但就我而言,我有一个使用 ECC 和 node-forge
不支持它.所以我找到了一个名为 node-openssl-wrapper
的模块,效果很好,因为它将 openssl 命令封装在一个简单的函数调用中,如下所示:
Dominykas' answer was good, but in my case, I have a certificate that uses ECC and node-forge
does not support it.
So I've found a module called node-openssl-wrapper
, which worked perfectly well because it encapsulates the openssl commands in a simple function call, like this:
co(function*() {
var ossl = require('openssl-wrapper');
var derCert = new Buffer('...'); // binary DER certificate
var pemCert = yield ossl.qExec('x509', derCert, { inform: 'der', outform: 'pem' });
});
相关文章