pkix路径生成失败

qybjjes1  于 2021-08-20  发布在  Java
关注(0)|答案(0)|浏览(229)

我正在尝试使用windows密钥库中的证书进行api调用
我的代码使用以下结构

  1. //Loading certificate
  2. KeyStore keyStore = KeyStore.getInstance("Windows-MY");
  3. keyStore .load(null, null);
  4. String alias = "Alias";
  5. X509Certificate certificate = (X509Certificate)keyStore.getCertificate(alias);
  6. TrustManagerFactory tmf = TrustManagerFactory
  7. .getInstance(TrustManagerFactory.getDefaultAlgorithm());
  8. //Making a keystore with just the needed certificate
  9. KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
  10. ks.load(null);
  11. ks.setCertificateEntry(alias, certificate);
  12. tmf.init(ks);
  13. SSLContext sslContext = SSLContext.getInstance("TLS");
  14. sslContext.init(null, tmf.getTrustManagers(), null);
  15. HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
  16. URL url = new URL("https://SERVER/SERVICE");
  17. HttpsURLConnection urlConn = (HttpsURLConnection) url.openConnection();
  18. //I'm getting the exception from below line
  19. System.out.println(urlConn.getResponseMessage());

我收到“sun.security.validator.validatorexception:pkix路径生成失败:sun.security.provider.certpath.suncertpathbuilderexception:找不到请求目标的有效证书路径”异常
在这一点上我几乎被卡住了。我在网上搜索了几个小时。有人能帮我解决这个问题吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题