如何从 .key 和 .crt 文件获取 .pem 文件?
如何从 SSL 证书创建 PEM 文件?
这些是我可用的文件:
.crt
server.csr
server.key
How can I create a PEM file from an SSL certificate?
These are the files that I have available:
.crt
server.csr
server.key
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(14)
您的密钥可能已经是 PEM 格式,但只是以 .crt 或 .key 命名。
如果文件内容以
-----BEGIN
开头,并且您可以在文本编辑器中读取它:该文件使用 base64,可以 ASCII 格式读取,而不是二进制格式。 该证书已经是 PEM 格式。 只需将扩展名更改为 .pem 即可。
如果文件是二进制文件:
对于 server.crt,您将使用
对于 server.key,使用
openssl rsa
代替openssl x509
。server.key 可能是您的私钥,.crt 文件是返回的签名 x509 证书。
如果这是针对 Web 服务器且您无法指定加载单独的私钥和公钥:
您可能需要连接这两个文件。 对于此用途:
我建议使用“includesprivatekey”命名文件,以帮助您管理对此文件保留的权限。
Your keys may already be in PEM format, but just named with .crt or .key.
If the file's content begins with
-----BEGIN
and you can read it in a text editor:The file uses base64, which is readable in ASCII, not binary format. The certificate is already in PEM format. Just change the extension to .pem.
If the file is in binary:
For the server.crt, you would use
For server.key, use
openssl rsa
in place ofopenssl x509
.The server.key is likely your private key, and the .crt file is the returned, signed, x509 certificate.
If this is for a Web server and you cannot specify loading a separate private and public key:
You may need to concatenate the two files. For this use:
I would recommend naming files with "includesprivatekey" to help you manage the permissions you keep with this file.
我需要为 AWS ELB 执行此操作。 在多次被对话框打败后,最后这对我有用:
谢谢 NCZ
编辑:正如 @floatingrock 所说
,使用 AWS,不要忘记在文件名前面加上
file://
。 所以它看起来像:http:// docs.aws.amazon.com/cli/latest/reference/iam/upload-server-certificate.html
I needed to do this for an AWS ELB. After getting beaten up by the dialog many times, finally this is what worked for me:
Thanks NCZ
Edit: As @floatingrock says
With AWS, don't forget to prepend the filename with
file://
. So it'll look like:http://docs.aws.amazon.com/cli/latest/reference/iam/upload-server-certificate.html
pem
文件包含证书和私钥。 这取决于您的证书/密钥的格式,但可能就像这样简单:A
pem
file contains the certificate and the private key. It depends on the format your certificate/key are in, but probably it's as simple as this:此外,如果您不希望它询问密码,则需要运行以下命令:
Additionally, if you don't want it to ask for a passphrase, then need to run the following command:
这是创建 .pem 文件的最佳选择
this is the best option to create .pem file
所有文件(*.crt、server.csr、server.key)可能已经是 PEM 格式,接下来如何处理这些文件取决于您想要如何使用它们,或者使用它们的工具以及格式这个需要。
我将在这里进一步解释用于存储加密材料的不同格式以及如何识别它们以及如何将一种格式转换为另一种格式。
标准
常见组合
这是要点解释了同样的事情+用于转换/验证/检查的命令。
总之,使用密码学/PKI 材料的典型步骤:
All of the files (*.crt, server.csr, server.key) may already be in PEM format, what to do next with these files depends on how you want to use them, or what tool is using them and in which format it requires.
I'll go a bit further here to explain what are the different formats used to store cryptography materials and how to recognise them as well as convert one to/from another.
Standards
Common combinations
This is a gist explains the same thing + commands for conversion/verification/inspection.
In conclusion, typical steps to work with cryptography/PKI materials:
我试图从 Godaddy 转向应用引擎。 诀窍是使用这一行:
完全按原样,但用我的域名替换名称(并不是说它真的很重要)
我回答了与通用名称/组织有关的所有问题 www.name.com
然后我打开了csr,复制它,将其粘贴到 go爸爸中,然后下载它,解压缩它,使用终端导航到解压缩的文件夹并输入:
然后我使用了 Google Apps 自定义域 SSL 出现问题:与
原样完全相同,只是我使用 name.unencrypted.priv 代替 privateKey.key。密钥,而不是 www_mydomain_com.crt,我使用 name.crt
然后我将 public.pem 上传到管理控制台以获取“PEM 编码的 X.509 证书”,并上传 private.pem 以获得“未加密的 PEM 编码的 RSA 私有证书”关键”
......这终于奏效了。
I was trying to go from godaddy to app engine. What did the trick was using this line:
Exactly as is, but replacing name with my domain name (not that it really even mattered)
And I answered all the questions pertaining to common name / organization as www.name.com
Then I opened the csr, copied it, pasted it in go daddy, then downloaded it, unzipped it, navigated to the unzipped folder with the terminal and entered:
Then I used these instructions from Trouble with Google Apps Custom Domain SSL, which were:
exactly as is, except instead of privateKey.key I used name.unencrypted.priv.key, and instead of www_mydomain_com.crt, I used name.crt
Then I uploaded the public.pem to the admin console for the "PEM encoded X.509 certificate", and uploaded the private.pem for the "Unencrypted PEM encoded RSA private key"..
.. And that finally worked.
在 Windows 上,您可以使用 certutil 工具:
您可以在 PowerShell 中将两个文件合并为一个,如下所示:
在 CMD 中,如下所示:
On Windows, you can use the
certutil
tool:You can combine both files to one in PowerShell like this:
And in CMD like this:
我观察到的是:如果使用 openssl 生成证书,它会捕获 crt 文件中的文本部分和 base64 证书部分。 严格的 pem 格式表示(wiki 定义)文件应以 BEGIN 开头和结尾结尾。
因此,对于某些需要严格 pem 格式的库(我在 java 中遇到过这种情况),生成的 crt 会因“无效 pem 格式”而无法通过验证。
即使您使用 BEGIN/ 复制或 grep 行END CERTIFICATE,并将其粘贴到 cert.pem 文件中,它应该可以工作。
这是我所做的,不是很干净,但对我有用,基本上它会过滤从 BEGIN 行开始的文本:
What I have observed is: if you use openssl to generate certificates, it captures both the text part and the base64 certificate part in the crt file. The strict pem format says (wiki definition) that the file should start and end with BEGIN and END.
So for some libraries (I encountered this in java) that expect strict pem format, the generated crt would fail the validation as an 'invalid pem format'.
Even if you copy or grep the lines with BEGIN/END CERTIFICATE, and paste it in a cert.pem file, it should work.
Here is what I do, not very clean, but works for me, basically it filters the text starting from BEGIN line:
尝试将 GoDaddy 证书上传到 AWS 时失败了好几次,但最终都非常简单。 无需将任何内容转换为 .pem。 您只需确保在链参数中包含 GoDaddy 捆绑证书,例如
要删除之前失败的上传,您可以执行以下操作
Trying to upload a GoDaddy certificate to AWS I failed several times, but in the end it was pretty simple. No need to convert anything to .pem. You just have to be sure to include the GoDaddy bundle certificate in the chain parameter, e.g.
And to delete your previous failed upload you can do
运行以下命令:
a)
openssl pkcs12 -in Certificates.p12 -out CertificateName.pem -nodes
,运行
Run below commands:
a)
openssl pkcs12 -in Certificates.p12 -out CertificateName.pem -nodes
,b)
openssl pkcs12 -in Certificates.p12 -out pushcert.pem -nodes -clcerts
首先,我们必须使用 .crt 文件和 .key 文件创建 pfx 文件。 在执行过程中,您需要输入您的证书密码。 命令
下面是获得 pfx 文件后的 。 请执行以下2条命令
First of all we have to create pfx file using .crt file and .key file. During execution you need to enter your certs password. Below is the command
Once you have pfx file. Please execute Below 2 commands
使用 p11-kit(在 CentOS 7 上可用)
给定的 crt 文件位于 /etc/ssl/certs/ 中:
每个 crt 文件的 pem 文件将被放置在指定的目录中(该命令将创建该目录)。
Using p11-kit (available on CentOS 7)
Given crt files are in /etc/ssl/certs/:
A pem file for each crt file will be placed in the specified directory (which the command will create).