⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e231. validating a certification path.txt

📁 这里面包含了一百多个JAVA源文件
💻 TXT
字号:
This example validates a chain of certificates using the most-trusted CAs in the JDK's cacerts file. 
    try {
        // Load the JDK's cacerts keystore file
        String filename = System.getProperty("java.home")
            + "/lib/security/cacerts".replace('/', File.separatorChar);
        FileInputStream is = new FileInputStream(filename);
        KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
        String password = "changeit";
        keystore.load(is, password.toCharArray());
    
        // Create the parameters for the validator
        PKIXParameters params = new PKIXParameters(keystore);
    
        // Disable CRL checking since we are not supplying any CRLs
        params.setRevocationEnabled(false);
    
        // Create the validator and validate the path
        // To create a path, see e229 Creating a Certification Path
        CertPathValidator certPathValidator
            = CertPathValidator.getInstance(CertPathValidator.getDefaultType());
        CertPathValidatorResult result = certPathValidator.validate(certPath, params);
    
        // Get the CA used to validate this path
        PKIXCertPathValidatorResult pkixResult = (PKIXCertPathValidatorResult)result;
        TrustAnchor ta = pkixResult.getTrustAnchor();
        X509Certificate cert = ta.getTrustedCert();
    } catch (CertificateException e) {
    } catch (KeyStoreException e) {
    } catch (NoSuchAlgorithmException e) {
    } catch (InvalidAlgorithmParameterException e) {
    } catch (CertPathValidatorException e) {
        // Validation failed
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -