NodeJS:以 DER 格式验证证书

NodeJS: Validate certificate in DER format(NodeJS:以 DER 格式验证证书)
本文介绍了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 的回答很好,但就我而言,我有一个使用 ECCnode-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 格式验证证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
Ordinals in words javascript(javascript中的序数)
getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)