crypto.parsePKCS12(bundle[, options])
bundle<ArrayBuffer> | <Buffer> | <TypedArray> | <DataView> 一个 DER 编码的 PKCS#12(.p12或.pfx)包。options<Object>passphrase<string> | <ArrayBuffer> | <Buffer> | <TypedArray> | <DataView> 保护该打包包的口令。省略此选项相当于传递''。
- 返回:<Object>
privateKey<KeyObject> | <null> 打包包里的第一个私钥,如果没有的话就是null。certificate<X509Certificate> | <null> 与privateKey匹配的证书,或者如果没有匹配的证书则使用null。additionalCertificates<X509Certificate[]> 打包包中的所有其他证书。如果没有私钥,本文件包含所有证书。可能为空。
解析一个 PKCS#12 包,通常存储为 .p12 或 .pfx 扩展名,并返回它的私钥和证书。
🌐 Parses a PKCS#12 bundle, commonly stored with a .p12 or .pfx extension,
and returns its private key and certificates.
import { parsePKCS12 } from 'node:crypto';
import { readFileSync } from 'node:fs';
const { privateKey, certificate, additionalCertificates } = parsePKCS12(
readFileSync('bundle.p12'),
{ passphrase: 'secret' },
);