在 Java 中使用没有密码的 p12 文件 [英] Using a p12 file without a password in Java

查看:44
本文介绍了在 Java 中使用没有密码的 p12 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尽我所能,我不知道如何在 Java 中使用没有密码的 .p12 文件.我尝试将 javax.net.ssl.keyStorePassword 设置为 "" 但无论我做什么,我都会收到以下 SSL 错误:

<块引用>

HTTP 传输错误:javax.net.ssl.SSLHandshakeException:握手期间远程主机关闭连接

我所有的谷歌搜索都表明,sun 实现不允许使用空密码,当然 keytool 不会让您在没有商店密码的情况下导入任何证书.

解决方案

Sun API 似乎需要密码,因此您需要在 .p12 文件中添加密码.

这个页面说你可以用 openssl 做到这一点将 .p12 转换为 .pem,然后转换回 .p12(但我还没有尝试过):

openssl pkcs12 -in cert.p12 -out temp.pem -passin pass: -passout pass:temppasswordopenssl pkcs12 -export -in temp.pem -out cert-final.p12 -passin pass:temppassword -passout pass:newpasswordrm -f temp.pem

另见这个相关问题.

Try as I might, I can't figure out how to use a .p12 file without a password in Java. I've tried setting javax.net.ssl.keyStorePassword to "" but whatever I do I get the following SSL error:

HTTP transport error: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake

All my googling would suggest that the sun implementation will not allow an empty password and of course the keytool won't let you import any certificate without a password for the store.

解决方案

The Sun API seems to require a password, so you will instead need to add a password to your .p12 file.

This page says that you can do this with openssl by converting the .p12 to a .pem, then converting back to a .p12 (but I have not tried it):

open­ssl pkcs12 -in cert.p12 -out temp.pem -passin pass: -passout pass:temppassword
open­ssl pkcs12 -export -in temp.pem -out cert-final.p12 -passin pass:temppassword -passout pass:newpa­ssword
rm -f temp.pem

See also this related question.

这篇关于在 Java 中使用没有密码的 p12 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆