To convert a .pem file into separate .crt (certificate) and .key (private key) files, you can use the openssl command-line tool. Here's how to do it:
Step 1: Understand the .pem File
A .pem file may contain several elements, such as:
- The private key.
- The public certificate.
- The certificate chain (optional).
Typically, the private key and public certificate are stored in the .pem file.
Step 2: Extract the Private Key
To extract the private key from the .pem file:
openssl pkey -in yourfile.pem -out private.key
in yourfile.pem: The input.pemfile.out private.key: The output file for the private key.
Step 3: Extract the Certificate
To extract the certificate from the .pem file:
openssl x509 -in yourfile.pem -out certificate.crt
in yourfile.pem: The input.pemfile.out certificate.crt: The output file for the certificate.
Summary of Commands
Extract private key:
openssl pkey -in yourfile.pem -out private.keyExtract certificate:
openssl x509 -in yourfile.pem -out certificate.crt
Example
If your .pem file is named combined.pem, you can use the following commands:
Extract the private key:
openssl pkey -in combined.pem -out private.keyExtract the certificate:
openssl x509 -in combined.pem -out certificate.crt
Explanation
- private.key: This file contains the private key extracted from the
.pemfile. - certificate.crt: This file contains the public certificate extracted from the
.pemfile.
Now, you have your private key in private.key and your certificate in certificate.crt. These files can be used as needed, for instance, in web server configurations or other services requiring separate certificate and key files.