Answer
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):
-----BEGIN CERTIFICATE-----
MIIG6DCCBNCgAwIBAgITMgAAGCeh8HZoCVDcnwAAAAAYJzANBgkqhkiG9w0BAQsF
ADBAMRUwEwYKCZImiZPyLGQBGRYFbG9jYWwxEzARBgoJkiaJk/IsZAEZFgNkb3Ix
EjAQBgNVBAMTCURPUi1TVUJDQTAeFw0yMDA1MDExNTI0MTJaFw0yMjA1MDExNTI0
MTJaMBYxFDASBgNVBAMTC3dwZG9yd2VibDE2MIIBIjANBgkqhkiG9w0BAQEFAAOC
...
-----END CERTIFICATE-----