I have a .cer certificate and I would like to convert it to the .pem format.

If I remember correctly, I used to be able to convert them by exporting the .cer in Base64, then renaming the file to .pem .

How do I convert a .cer certificate to .pem?

6 Answers 6


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

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


  • 24
    Doesn't work for me. The CER file is exported from the Windows certificate export tool. It has the following form: -----BEGIN CERTIFICATE----- MII...D2H -----END CERTIFICATE-----. From openssl, I get the following error: error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag:tasn_dec.c:1338: error:0D07803A:asn1 encoding routines:ASN1_ITEM_EX_D2I:nested asn1 error:tasn_dec.c:390:Type=X509 Nov 14, 2016 at 0:27
  • 51
    Then your certificate is already in PEM format. Just rename it from certificate.cer to certificate.pem.
    – slowhand
    May 16, 2017 at 21:11
  • Earlier asked here – How to convert .crt to .pem Sep 4, 2021 at 14:41

convert a .cer file in .pem

open a terminal and run the following command

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

Where certificate.cer is the source certificate file you want to convert and certificate.pem is the name of the converted certificate.


When openssl is not available on your system you could alternatively convert certificates with the java keytool.

However you have to create a java keystore (JKS) first. The certificates can then be imported and exported in different formats.

keytool -genkey -alias test -keystore <key store file>
keytool -delete -alias test -keystore <key store file>

Converting from DER to PEM:

keytool -import -trustcacerts -alias test -file <der certificate file> -keystore test.keystore 
keytool -exportcert -alias test -file <pem certificate file> -rfc -keystore test.keystore

This blog post explains how to convert certificate formats in detail

  • I did this and the .pem file is almost identical to the .cer file, just wrapped differently.
    – endolith
    May 6, 2016 at 15:00
  • 2
    @endolith in that case they are both .pem files. A .cer file can be .der or .pem encoded, this question assumes .der encoding, which you did not have.
    – eis
    Sep 20, 2016 at 15:00


  • If your certificate is exported with DER encoding, then use the accepted answer:

    openssl x509 -inform der -in certificate.cer -out certificate.pem
  • If your certificate is exported with Base-64 encoding, then rename the file's extension from .cer to .pem since the file is already in .pem format.

How to tell that your .cer file is in .pem format?

See this stack-o answer, quoted here:

A .pem format certificate file will most likely be ASCII-readable. It will have a line that starts with:
...followed by Base-64 encoded data, followed by a
at the end. There may be other lines before or after.

For example, a .pem certificate (shortened):


We mustn't forget that Windows can do this natively:

certutil.exe -encode <der file> <pem file>

and in the other direction:

certutil.exe -decode <pem file> <der file>

It works with certificates and PKCS#10 requests.


Just changing the file extension worked for me:

mv filename.cer filename.pem

  • 2
    That only works if the content of the file is already PEM encoded. Changing the file extension does not change the content of the file. In many cases, a program would also not care if the file extension is der or pem, and rather check the content.
    – Mime
    Jul 6, 2022 at 13:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .