如何从SSL证书创建PEM文件?

这些是我有可用的文件:

.crt server.csr server.key


当前回答

此外,如果你不希望它要求一个密码短语,那么需要运行以下命令:

openssl rsa -in server.key -out server.key

其他回答

在Windows上,你可以使用certutil工具:

certutil -encode server.crt cert.pem
certutil -encode server.key key.pem

你可以在PowerShell中将两个文件合并为一个文件,如下所示:

Get-Content cert.pem, key.pem | Set-Content cert-and-key.pem

在CMD中,像这样:

copy cert.pem+key.pem cert-and-key.pem /b

通过appleId从临时门户下载证书, 从密钥链导出证书并给出名称(Certificates.p12), 打开终端和goto文件夹,你保存上述证书。p12文件, 执行以下命令: a) openssl pkcs12 -in证书。p12 -out CertificateName. p12pem节点, b) openssl pkcs12 -in证书。P12 -out pushcert。Pem -nodes -clcerts 您的。pem文件准备“pushcert.pem”。

我观察到的是:如果您使用openssl来生成证书,它会捕获crt文件中的文本部分和base64证书部分。严格的pem格式表示(wiki定义)文件应该以BEGIN和end开始和结束。

.pem -(隐私增强邮件)Base64编码DER证书, 附上证书”——开始——“和”——之间结束 证书——”

因此,对于一些库(我在java中遇到过这种情况),期望严格的pem格式,生成的crt会作为“无效的pem格式”验证失败。

即使您使用BEGIN/END CERTIFICATE复制或grep这些行,并将其粘贴到cert.pem文件中,它也应该可以工作。

以下是我所做的,不是很干净,但对我来说很有用,基本上它从BEGIN行开始过滤文本:

grep -A 1000 BEGIN cert.crt > cert.pem .pem

我需要为AWS ELB这样做。在被对话框打了很多次之后,这终于对我有用了:

openssl rsa -in server.key -text > private.pem
openssl x509 -inform PEM -in server.crt > public.pem

谢谢NCZ

编辑:正如@floatingrock所说

使用AWS时,不要忘记在文件名前加上file://。它看起来是这样的:

 aws iam upload-server-certificate --server-certificate-name blah --certificate-body file://path/to/server.crt --private-key file://path/to/private.key --path /cloudfront/static/

http://docs.aws.amazon.com/cli/latest/reference/iam/upload-server-certificate.html

这是创建.pem文件的最佳选项

openssl pkcs12 -in MyPushApp.p12 -out MyPushApp.pem -nodes -clcerts