从Windows证书管理器导出不可导出CER证书私钥时OpenSSL加载私钥失败的问题求助
我和很多人一样,正尝试导出和.cer文件关联的私钥,用来转换成.pfx格式。网上能找到不少偏门的解决方案,但我专门关注了一种不需要第三方工具的方法,跟着步骤操作后,确实导出了一段看起来像是私钥的内容。
我的操作步骤
我把生成的XML格式.reg文件里<BA>标签中的内容复制出来,做成了一个.key文件,格式如下:
-----BEGIN RSA PRIVATE KEY----- <BA>标签内容 -----END RSA PRIVATE KEY-----
接着我用OpenSSL命令尝试生成pfx文件(其中test.cer是从Windows证书存储导出的证书):
openssl pkcs12 -export -out test.pfx -inkey test.key -in test.cer
遇到的错误
运行上面的命令后,我得到了如下错误信息:
unable to load private key
10208:error:0D0680A8:asn1 encoding routines:asn1_check_tlen:wrong tag:crypto\asn1\tasn_dec.c:1149:
10208:error:0D06C03A:asn1 encoding routines:asn1_d2i_ex_primitive:nested asn1 error:crypto\asn1\tasn_dec.c:713:
10208:error:0D08303A:asn1 encoding routines:asn1_template_noexp_d2i:nested asn1 error:crypto\asn1\tasn_dec.c:646:Field=version, Type=RSAPrivateKey
10208:error:04093004:rsa routines:old_rsa_priv_decode:RSA lib:crypto\rsa\rsa_ameth.c:142:
10208:error:0D0680A8:asn1 encoding routines:asn1_check_tlen:wrong tag:crypto\asn1\tasn_dec.c:1149:
10208:error:0D06C03A:asn1 encoding routines:asn1_d2i_ex_primitive:nested asn1 error:crypto\asn1\tasn_dec.c:713:
10208:error:0D08303A:asn1 encoding routines:asn1_template_noexp_d2i:nested asn1 error:crypto\asn1\tasn_dec.c:646:Field=version, Type=PKCS8_PRIV_KEY_INFO
10208:error:0907B00D:PEM routines:PEM_read_bio_PrivateKey:ASN1 lib:crypto\pem\pem_pkey.c:88:
我的疑问
我想到两个可能的问题原因,但不知道该怎么排查:
- 我给.key文件设置的页眉页脚加密标签不正确
<BA>标签里的内容其实根本不是私钥
如果是第一个原因,正确的页眉页脚应该是什么?
如果是第二个原因,那这段内容到底是什么?会不会是.cer文件对应的公钥?
备注:内容来源于stack exchange,提问作者Sterling Butters




