Node.js - crypto.js - PFX报头太长

Node.js - crypto.js - PFX header too long

本文关键字:js 报头 crypto Node PFX      更新时间:2023-09-26

我正试图从文件中加载PFX和密码短语,以便我可以发出HTTPS请求。在我开始之前,我已经知道PFX是好的,这不是问题。

我正在做以下事情:

config.options.pfx = fs.readFileSync('file.pfx');
config.options.passphrase = 'passphrase';

我正在把我的选项传递给代理。

config.options.agent = new https.Agent(options);

然后尝试构建请求,得到以下错误:

crypto.js:143
      c.context.loadPKCS12(pfx, passphrase);
            ^
Error: header too long
    at Object.exports.createCredentials (crypto.js:143:17)
    at Object.exports.connect (tls.js:1334:27)
    at Agent.createConnection (https.js:79:14)
    at Agent.createSocket (http.js:1293:16)
    at Agent.addRequest (http.js:1269:23)
    at new ClientRequest (http.js:1416:16)
    at Object.exports.request (https.js:123:10)

我从一个工作存储库中检查了这个,我知道这对它的原作者是有效的。但是,由于某些原因,我的设置没有运行它。

我也遇到过类似的问题。事实证明,我使用的是fs.readFileSync('file.pfx', 'utf8'),这对于PEM文件是正确的,但由于PKCS12文件是二进制的,您应该只传递fs.readFileSync('file.pfx')

我有同样的问题,但在我的情况下,我使用

pfx: fs.readFileSync('certs/keystore.p12')

在我的情况下,问题是我使用的pfx不是正确地从jks生成的。使用keytool导出是正确的解决方案

keytool -v -importkeystore -srckeystore keystore.jks -destkeystore keystore.p12 -deststoretype PKCS12