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?

4 Answers 4


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

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


  • 20
    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
  • 38
    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 Base64 encoding, then rename the extension .cer to .pem. 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 will most likely be ASCII-readable. It will have a line -----BEGIN CERTIFICATE-----, followed by base64-encoded data, followed by a line -----END CERTIFICATE-----. There may be other lines before or after.

For example, a .pem certificate (shortened):


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.