問題描述
我正在使用 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' });
});
這篇關于NodeJS:以 DER 格式驗證證書的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!