使用openssl将多个证书加载到PKCS12中

Moh*_*aei 20 openssl pkcs#12 x509certificate

我正在尝试使用openssl将多个证书加载到PKCS12格式中.命令如下:

openssl pkcs12 -export -in cert1.arm -inkey cert1_private_key.pem -certfile cert2.arm -certfile cert3.arm -certfile RootCert.pem -name "Test" -out test.p12
Run Code Online (Sandbox Code Playgroud)

解析生成的PKCS12文件后,只有最后一个证书已包含在文件中:

openssl pkcs12 -in test.p12 -info -nodes
Run Code Online (Sandbox Code Playgroud)

我还尝试将它们单独导入到pkcs12文件中,而在所有尝试中,只有最后一个证书保留在文件中.

有什么想法解决它的问题?

gtr*_*rig 20

首先,确保所有证书都是PEM格式.然后,创建一个名为"certs.pem"的SINGLE文件,其中包含其余的证书(cert2.arm,cert3.arm和RootCert.pem).

然后使用如下命令:

openssl pkcs12 -export -in cert1.arm -inkey cert1_private_key.pem -certfile certs.pem -name "Test" -out test.p12
Run Code Online (Sandbox Code Playgroud)

OpenSSL的PKCS12文档解释了不同的选择.

  • 您可以将单个文件连接到用于创建pkcs12文件的同一命令行上的组合文件中.例如在Windows中,`type cert2.arm cert3.arm RootCert.pem> combined.pem&openssl pkcs12 ...`.在Linux/Unix中,你可以做`cat cert2.arm cert3.arm RootCert.pem> combined.pem; openssl pkcs12 ......` (3认同)
  • 有什么方法可以使用 `openssl` 将证书*添加*到现有的 `pkcs12` 文件中吗?我知道你可以从头开始组装一个,但是只添加一个呢? (3认同)
  • @ChristopherSchultz 我也在努力解决这个问题。我相信只有 Java 的 keytool 才能正确处理这个问题。 (3认同)