【发布时间】:2019-01-31 21:49:00
【问题描述】:
我已经按照steps listed here 创建了一个新的私钥和证书。现在我正在尝试将它们组合成一个 .pfx 文件。
OpenSSL 应该能够从单个文件中读取私钥和证书,并且根据 man man 文档,还应该能够从 stdin 中读取。但是,这似乎对我不起作用。
在 Mac OS X 10.14.3 和 openssl version 上提供“LibreSSL 2.6.5”。
我将我的证书和密钥合并到一个文件中(称为“combined.pem”)。我使用以下命令做到了这一点:
$ openssl genrsa -out private.key 2048
$ openssl req -new -x509 -key private.key -out public.cer -days 365
$ cat public.cer >> combined.pem
$ cat private.key >> combined.pem
作为参考,combined.pem 看起来像这样:
-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----
-----BEGIN RSA PRIVATE KEY-----
...
-----END RSA PRIVATE KEY-----
当我运行以下命令时,一切正常:
$ openssl pkcs12 -export -out x509.pfx -in combined.pem
当我运行这个命令时,我得到一个错误:
$ openssl pkcs12 -export -out x509.pfx < combined.pem
unable to load certificates
我也试过了:
$ cat combined.pem | openssl pkcs12 -export -out x509.pfx
unable to load certificates
我错过了什么? OpenSSL 真的不能从stdin 读取这个吗?
另外,来自man 文档:
-in file
The input file to read from, or standard input if not specified. The order doesn't matter but one private key and its corresponding certificate should
be present. If additional certificates are present, they will also be included in the PKCS#12 file.
-inkey file
File to read a private key from. If not present, a private key must be present in the input file.
【问题讨论】: