Linux 将 cer 转换为 pem 时出现 OpenSSL 编码错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14191468/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
OpenSSL encoding errors while converting cer to pem
提问by Arthur Kushman
I`m trying to convert the .cer file to .pem through openssl, the command is:
我正在尝试通过openssl将.cer文件转换为.pem,命令是:
openssl x509 -inform der -in certnew.cer -out ymcert.pem
and that's the errors I`m getting:
这就是我得到的错误:
unable to load certificate
140735105180124:error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag:tasn_dec.c:1319:
140735105180124:error:0D07803A:asn1 encoding routines:ASN1_ITEM_EX_D2I:nested asn1 error:tasn_dec.c:381:Type=X509
What am I doing wrong?
我究竟做错了什么?
采纳答案by L0g0ff
I had this problem also. Just rename the CER to PEM was enough :)
我也有这个问题。只需将 CER 重命名为 PEM 就足够了:)
回答by eis
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.
为了扩展现有答案,如ssl.com 所解释的,.cer 文件可以是 der 或 pem 编码。如果是 der 编码,则需要像之前那样进行转换,但如果它已经是 pem 编码,则不需要转换,如果尝试,则会出现错误 - 您只需重命名文件。
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:
如果您不确定,最好知道 .der 是一种二进制格式,而 .pem 是 ascii 格式。如果您将证书的内容回显出来,.pem 文件将如下所示:
-----BEGIN CERTIFICATE-----
MIIEuTCCA6G[snip lots of chars]
XmCpajQ==
-----END CERTIFICATE-----
And a .der file would look like this:
.der 文件如下所示:
0??0???@*?H?????0
0??1
0 UUS10U
VeriSign, Inc.10U
VeriSign Trust Network1:08U
回答by tarkos
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.
我有类似的 CRT 格式问题,在转换为 pem 时会出错。我做同样的事情,比如 L0g0ff 并且它有效。下面有更多细节。
I checked details of certificate:
openssl x509 -in certificate.crt -noout -text
after changing extension to from certificate.crt to certificate.pem I get file in expected format:
我检查了证书的详细信息:
openssl x509 -in certificate.crt -noout -text
将扩展名从certificate.crt更改为certificate.pem后,我得到了预期格式的文件:
-----BEGIN CERTIFICATE-----
...........................
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
...........................
-----END CERTIFICATE-----