如何在 Linux 中转换 SSL 证书

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16583428/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 22:57:18  来源:igfitidea点击:

How to convert an SSL certificate in linux

linuxsslopensslcertificate

提问by Dropout

Is there a way how to convert certificates between cer/pem/crt/der/pfx/p12 in Linux? I have an SSL certificate in a .cer file and I need it to be .pem in order to use it.

有没有办法在Linux中的cer/pem/crt/der/pfx/p12之间转换证书?我在 .cer 文件中有一个 SSL 证书,我需要它是 .pem 才能使用它。

How can I convert it?

我怎样才能转换它?

采纳答案by Dropout

Converting certificates between cer/pem/crt/der/pfx/p12 can be done in Linux with the use of OpenSSLtool via the terminal.

可以在 Linux 中通过终端使用OpenSSL工具在 cer/pem/crt/der/pfx/p12 之间转换证书。

These commands allow you to convert certificates and keys to different formats to make them compatible with specific types of servers or software.

这些命令允许您将证书和密钥转换为不同的格式,以使其与特定类型的服务器或软件兼容。

Convert a DER file (.crt .cer .der) to PEM

将 DER 文件 (.crt .cer .der) 转换为 PEM

openssl x509 -inform der -in certificate.cer -out certificate.pem

openssl x509 -inform der -in certificate.cer -out certificate.pem

Convert a PEM file to DER

将 PEM 文件转换为 DER

openssl x509 -outform der -in certificate.pem -out certificate.der

openssl x509 -outform der -in certificate.pem -out certificate.der

Convert a PKCS#12 file (.pfx .p12) containing a private key and certificates to PEM

将包含私钥和证书的 PKCS#12 文件 (.pfx .p12) 转换为 PEM

openssl pkcs12 -in keyStore.pfx -out keyStore.pem -nodes

openssl pkcs12 -in keyStore.pfx -out keyStore.pem -nodes

You can add -nocerts to only output the private key or add -nokeys to only output the certificates.

您可以添加 -nocerts 以仅输出私钥或添加 -nokeys 以仅输出证书。

Convert a PEM certificate file and a private key to PKCS#12 (.pfx .p12)

将 PEM 证书文件和私钥转换为 PKCS#12 (.pfx .p12)

openssl pkcs12 -export -out certificate.pfx -inkey privateKey.key -in certificate.crt -certfile CACert.crt

openssl pkcs12 -export -out certificate.pfx -inkey privateKey.key -in certificate.crt -certfile CACert.crt

For more information see:

有关更多信息,请参阅:

http://www.sslshopper.com/article-most-common-openssl-commands.html

https://support.ssl.com/index.php?/Knowledgebase/Article/View/19

http://www.sslshopper.com/article-most-common-openssl-commands.html

https://support.ssl.com/index.php?/Knowledgebase/Article/View/19

回答by kishore tiwari

Convert .crt to .p12

将 .crt 转换为 .p12

openssl pkcs12 -export -out server.p12 -inkey server.key -in server.crt

openssl pkcs12 -export -out server.p12 -inkey server.key -in server.crt

Where server.key , is the server key . server.crt is cert file from CA or self sigh

其中 server.key 是服务器密钥。server.crt 是来自 CA 的证书文件或自我叹息