OpenSSL encoding errors while converting cer to pem

后端 未结 4 2094
遥遥无期
遥遥无期 2020-12-17 08:51

I`m trying to convert the .cer file to .pem through openssl, the command is:

openssl x509 -inform der -in certnew.cer -out ymcert.pem

and t

相关标签:
4条回答
  • 2020-12-17 08:55

    To expand on existing answer, like explained by ssl.com, a .cer file can be either in der or pem encoding. If it is in der encoding, you'll need to do conversion like you have done, but if it is already in pem encoding, no conversion is necessary and you get the error you've got if you try - and you can just rename the file.

    If you're unsure, it is good to know that .der is a binary format, whereas .pem is ascii one. If you echo the contents of your certificate out, a .pem file would look something like this:

    -----BEGIN CERTIFICATE-----
    MIIEuTCCA6G[snip lots of chars]
    XmCpajQ==
    -----END CERTIFICATE-----
    

    And a .der file would look like this:

    0▒▒0▒▒▒@*▒H▒▒▒▒▒0
    0▒▒1
        0   UUS10U
    VeriSign, Inc.10U
                     VeriSign Trust Network1:08U
    
    0 讨论(0)
  • 2020-12-17 08:56

    no need to convert the file from .cer to .pem you just need to use this command and desired result will be get openssl x509 -inform pem -in certificate.cer -pubkey -noout > certificate_publickey.pem it all depends on which encoding type used to generate the certificate as mentioned by @eis

    0 讨论(0)
  • 2020-12-17 09:05

    I have similar issue with CRT format which give me error during converting to pem. I do same thing like L0g0ff and it works. Below more details.

    1. I checked details of certificate:

      openssl x509 -in certificate.crt -noout -text

    2. after changing extension to from certificate.crt to certificate.pem I get file in expected format:

    -----BEGIN CERTIFICATE----- ........................... -----END CERTIFICATE-----

    0 讨论(0)
  • 2020-12-17 09:09

    I had this problem also. Just rename the CER to PEM was enough :)

    0 讨论(0)
提交回复
热议问题