Converting .cer to .pem errors

opensslssl-certificate

I realize that there are multiple posts about converting .cer to .pem, but none actually mention issues regarding the coversion. I have a cert named Cert.cer (original, I know) that I'm trying to convert to Cert_PEM.pem using the following command:

openssl x509 -inform der -in Cert.cer -out Cert_PEM.pem

In doing so I run into this error:

13892:error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag:tasn_dec.c:1316:
13892:error:0D07803A:asn1 encoding routines:ASN1_ITEM_EX_D2I:nested asn1 error:tasn_dec.c:380:Type=X509

I have some knowledge of certs, SSL and encryption, but this goes beyond the current scope of it.

EDIT: Here are the first 4 lines of the cert:

-----BEGIN CERTIFICATE-----
MIIC6DCCAdACAQMwDQYJKoZIhvcNAQEFBQAwgYQxCzAJBgNVBAYTAlVTMQ4wDAYD
VQQIEwVUZXhhczEPMA0GA1UEBxMGQXVzdGluMS4wLAYDVQQLEyVNb3RpdmUgU2Vy
dmVyIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MQ8wDQYDVQQKEwZNb3RpdmUxEzAR

Any help would be excellent!

Best Answer

What you have is a PEM-encoded .cer file. Converting may be as easy as changing the file extension. SSL-file formats are legion and der-encoding is actually not that common.

A general rule of thumb is:

  • If looks like base64 encoding, it's probably PEM-encoded.
  • If it looks like cat-ing a binary file, it's probably DER-encoded.