我正在尝试使用windows密钥库中的证书进行api调用
我的代码使用以下结构
//Loading certificate
KeyStore keyStore = KeyStore.getInstance("Windows-MY");
keyStore .load(null, null);
String alias = "Alias";
X509Certificate certificate = (X509Certificate)keyStore.getCertificate(alias);
TrustManagerFactory tmf = TrustManagerFactory
.getInstance(TrustManagerFactory.getDefaultAlgorithm());
//Making a keystore with just the needed certificate
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(null);
ks.setCertificateEntry(alias, certificate);
tmf.init(ks);
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, tmf.getTrustManagers(), null);
HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
URL url = new URL("https://SERVER/SERVICE");
HttpsURLConnection urlConn = (HttpsURLConnection) url.openConnection();
//I'm getting the exception from below line
System.out.println(urlConn.getResponseMessage());
我收到“sun.security.validator.validatorexception:pkix路径生成失败:sun.security.provider.certpath.suncertpathbuilderexception:找不到请求目标的有效证书路径”异常
在这一点上我几乎被卡住了。我在网上搜索了几个小时。有人能帮我解决这个问题吗?
暂无答案!
目前还没有任何答案,快来回答吧!