NodeJS - 从 P7B 文件获取证书链

NodeJS - Get certificate Chain from P7B file

我正在尝试使用 CMS base64 编码字符串,将其转换为 pkcs7 文件并使用 javascript/nodejs 提取叶证书和中间证书,类似于以下 openssl 命令:

openssl pkcs7 -print_certs -in certificate.p7b -out certificate.cer

我几乎阅读了每篇文章并看到了其他语言的解决方案,但不是针对节点的。我知道你可以使用 node-forge 实现我需要的,但是 node-forge 不支持 ECC 算法。有人知道可以帮助我完成此任务的任何其他 solutions/npm 软件包吗?请帮我。我对此很陌生。

您是否看到 PKI.js for Node.js? It is a pure JavaScript library implementing the formats that are used in PKI applications. It is based on the W3C Web Cryptography API 完全支持 CMS 消息中的所有 "Suite B" 算法。 OP 提交的代码片段:

const cmsSignedBuffer = stringToArrayBuffer(fromBase64(token.signature)); 
const asn1 = asn1js.fromBER(cmsSignedBuffer); 
const cmsContentSimpl = new pkijs.ContentInfo({ schema: asn1.result }); 
const cmsSignedSimpl = new pkijs.SignedData({ schema: cmsContentSimpl.content })

另一种方法是使用 openssl 的包装器,例如 openssl-nodejs。包装器只是生成一个子进程来调用 openssl。因此,必须在部署 Node.js 应用程序的系统上安装 openssl。