如何从.key和.crt文件获取.pem文件? [英] How to get .pem file from .key and .crt files?

查看:943
本文介绍了如何从.key和.crt文件获取.pem文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How can I create a PEM file from an SSL certificate?

这些是我可以使用的文件:

These are the files that I have available:

  • .crt
  • server.csr
  • server.key
  • .crt
  • server.csr
  • server.key

推荐答案

您的密钥可能已经是PEM格式,而只是用.crt或.key命名.

Your keys may already be in PEM format, but just named with .crt or .key.

如果文件的内容以-----BEGIN开头,并且您可以在文本编辑器中阅读该文件:

If the file's content begins with -----BEGIN and you can read it in a text editor:

该文件使用base64,它可以ASCII格式读取,而不是二进制格式.证书已经是PEM格式.只需将扩展名更改为.pem.

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.

如果文件为二进制文件:

对于server.crt,您将使用

For the server.crt, you would use

openssl x509 -inform DER -outform PEM -in server.crt -out server.crt.pem

对于server.key,请使用openssl rsa代替openssl x509.

For server.key, use openssl rsa in place of openssl x509.

server.key可能是您的私钥,.crt文件是返回的,签名的x509证书.

The server.key is likely your private key, and the .crt file is the returned, signed, x509 certificate.

如果这是针对Web服务器的,并且您不能指定加载单独的私钥和公钥:

您可能需要串联两个文件.为此用途:

You may need to concatenate the two files. For this use:

cat server.crt server.key > server.includesprivatekey.pem

我建议使用"includesprivatekey"命名文件,以帮助您管理对该文件保留的权限.

I would recommend naming files with "includesprivatekey" to help you manage the permissions you keep with this file.

这篇关于如何从.key和.crt文件获取.pem文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆