Java 使用中间证书验证证书路径

Java 使用中间证书验证证书路径,java,security,Java,Security,我正在尝试使用域证书和中间证书验证证书路径。证书不包含根证书。是否有方法在未提供根证书的情况下验证证书路径 谢谢 --更新-- 我尝试过的方法 InputStream trustStoreInput = new FileInputStream(cacertPath); String password = password; KeyStore anchors = KeyStore.getInstance(KeyStore.getDefaultTyp

我正在尝试使用域证书和中间证书验证证书路径。证书不包含根证书。是否有方法在未提供根证书的情况下验证证书路径

谢谢

--更新-- 我尝试过的方法

        InputStream trustStoreInput = new FileInputStream(cacertPath);
        String password = password;

        KeyStore anchors = KeyStore.getInstance(KeyStore.getDefaultType());
        anchors.load(trustStoreInput, password.toCharArray());
        X509CertSelector target = new X509CertSelector();

        target.setCertificate(certList.get(1)); <---I have domain cert and intermediate cert
        PKIXBuilderParameters params = new PKIXBuilderParameters(anchors, target);
        CertStoreParameters intermediates = new CollectionCertStoreParameters(certList);
        params.addCertStore(CertStore.getInstance("Collection", intermediates));
        CertPathBuilderResult result = CertPathBuilder.getInstance("PKIX").build(params);

欢迎来到StackOverflow。你能告诉我们到目前为止你都做了些什么吗?另外,请尝试使用搜索功能,因为问题已经得到回答。例如,Thx for reply,我已经尝试了您的解决方案,但它在cf.generateCertPathWhat type certificate you using?PEM格式的Ssl certificate上出错。它包含服务器证书和中间证书。您的证书中是否包含中间证书?或者我假设X509是根CA认证的SSL证书?
 unable to find valid certification path to requested target