Security

How Do I Convert a CER File to PEM?

There can be different reasons that you want to convert your security certificates to other formats. One of the reasons is when your system is not accepting the existing format or if your security certificate file is not compatible with the application. Whatever your reason for converting formats for the security certificates files is, you can easily do so using the most convenient and reliable OpenSSL utility.

OpenSSL is an open-source full-featured command-line utility that is usually used for generating CSR and private keys, installing SSL/TLS certificates, converting security certificate formats, etc.

In today’s post, we will describe how to convert a CER file to PEM.

Note: The commands shown here have been demonstrated on Ubuntu 20.04 LTS Terminal. To open the Terminal in Ubuntu desktop, hit the super key and launch it from the Applications menu or use the Ctrl+Alt+T shortcut to open it.

CER File

A CER file is a security file used to store X.509 certificate. It is provided and issued by CA (certificate authority) that verifies the authenticity of a website. It contains information about the certificate owner and public key.

PEM File

PEM (Privacy Enhanced Mail) is the bas64 encoded ASCII files that certificates’ authorities issue certificates in. This format is used for storing and sending cryptographic keys and certificates and other intermediate certificates.

Converting a CER File to PEM

OpenSSL toolkit is by default installed in Ubuntu. However, if it is not there, you can install it through the following command in Terminal:

$ sudo apt install openssl

Enter sudo password. When you are prompted with the y/n option, hit y to carry on. After that, it will begin installing OpenSSL on the system.

To convert a CER file to PEM, use the following syntax:

$ openssl x509 -inform der -in cert.cer -outform pem -out cert.pem

In the above syntax, cert.cer is the name of the security certificate you want to convert in PEM format and cert.pem is the name of the file after conversion.

Converting PEM to CER

To convert a PEM file to CER, use the following syntax:

$ openssl x509 -inform PEM -in cert.pem -outform DER -out cert.cer

In the above syntax, cert.pem is the name of the security certificate you want to convert in CER format, and cert.cer is the name of the certificate after conversion.

This is how you can convert a CER file to PEM using the OpenSSL utility.  Hope it helps!

About the author

Karim Buzdar

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. He blogs at LinuxWays.