我正在尝试连接到需要 PKCS12
证书的 SSL
网络服务。
问题:是否可以不将证书安装到本地 keystore ,而是在运行时动态加载?
我试过如下:
static {
KeyStore.getInstance("PKCS12").load(this.getClass().getClassLoader()
.getResourceAsStream("myfile.p12"), "password".toCharArray());
}
但是结果:
sun.security.validator.ValidatorException: PKIX path building failed. sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target.
显然它不起作用。但是为什么?
旁注:链接的 SO 问题没有回答我的问题,因为它针对 trustStore
,但我的问题是关于 keystore
。
最佳答案
问题与这段代码无关。您的truststore 不信任服务器的 证书。如果它是自签名的,则必须导入它。更好的是,让它由 CA 签名。
关于java - 如何在不安装到 keystore 的情况下连接到 SSL 证书 Web 服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35887985/