【问题标题】:Node.js - crypto.js - PFX header too longNode.js - crypto.js - PFX 标头太长
【发布时间】:2014-08-15 01:35:20
【问题描述】:

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

我正在做以下事情:

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

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

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

然后我尝试构建 rquest,但出现以下错误:

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)

我从一个工作存储库中检查了这个,我知道这适用于它的原始作者。不过,出于某种原因,我的设置没有运行它。

【问题讨论】:

  • 提示:pfx 只是一个被 MS 搞砸的 PKCS12 版本,因此一些加密工具可以与 pfx 一起使用,而其他工具则不能。尝试使用 openssl 工具生成本机 PKCS12 或将 pfx 转换为 PKCS12。
  • 我在使用有效的 PFX (PKCS12) 文件时遇到了完全相同的问题,但没有解决方案。你解决了吗?

标签: javascript node.js https pfx


【解决方案1】:

我遇到了类似的问题。原来我使用的是fs.readFileSync('file.pfx', 'utf8'),这对于 PEM 文件是正确的,但由于 PKCS12 文件是二进制文件,所以你应该传入 fs.readFileSync('file.pfx')

【讨论】:

  • 谢谢,这对我很有帮助!
【解决方案2】:

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

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多