Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get .pem file from .key and .crt files?

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

These are the files that I have available:

  • .crt
  • server.csr
  • server.key
like image 323
Sergio Rodriguez Avatar asked Jun 13 '09 23:06

Sergio Rodriguez


People also ask

Is a PEM file a CRT file?

A . pem file is a container format that may just include the public certificate or the entire certificate chain (private key, public key, root certificates): Private Key. Server Certificate (crt, puplic key)

Is PEM and CRT the same?

pem adds a file with chained intermediate and root certificates (such as a . ca-bundle file downloaded from SSL.com), and -inkey PRIVATEKEY. key adds the private key for CERTIFICATE. crt (the end-entity certificate).


1 Answers

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

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

For server.key, use openssl rsa in place of openssl 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:

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

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

like image 184
maxwellb Avatar answered Sep 20 '22 08:09

maxwellb