最近测试脚本的语言用ruby写了,因为涉及到证书通讯,而公司服务证书生成的是jks证书,而ruby中用的证书为openssl x509 的pem格式。
从网上看到先把jks证书转为p12证书,然后再从p12证书转为pem证书。
sert.jks 转为 sert.p12
keytool -importkeystore -srckeystore sert.jks -destkeystore sert.p12 -srcstoretype jks -deststoretype pkcs12sert.p12 转为 sert.pem
openssl pkcs12 -in sert.p12 -out sert.pem
但第一步执行结束后,发现错误:Problem importing entry for alias caroot: java.security.KeyStoreException: TrustedCertEntry not supported.
从网上找了很多页面都无法解决这个问题。
历经千辛万苦终于解决,解决方案如下:
sert.jks 转为 sert.p12
keytool -importkeystore -srckeystore sert.jks -destkeystore sert.p12 -srcstoretype jks -deststoretype pkcs12 -alias keyOwnerAliassert.p12 转为 sert.pem
openssl pkcs12 -in sert.p12 -out sert.pem
加了-alias keyOwnerAlias 关键字之后,就没有再出现这个错误,希望能对一些碰到同样问题的朋友能够提供帮助。
keyOwnerAlias 就是这个证书拥有者的别名,需要和证书里用到的别名一致。
别名没有试过中文的。有兴趣的朋友可以尝试一下。