当前位置: 首页>>代码示例>>Java>>正文


Java SunCertPathBuilderException类代码示例

本文整理汇总了Java中sun.security.provider.certpath.SunCertPathBuilderException的典型用法代码示例。如果您正苦于以下问题:Java SunCertPathBuilderException类的具体用法?Java SunCertPathBuilderException怎么用?Java SunCertPathBuilderException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SunCertPathBuilderException类属于sun.security.provider.certpath包,在下文中一共展示了SunCertPathBuilderException类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import sun.security.provider.certpath.SunCertPathBuilderException; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    try {
        CertPathBuilder cpb = CertPathBuilder.
            getInstance(CertPathBuilder.getDefaultType());
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        File f = new File
            (System.getProperty("test.src", "."), "speech2speech");
        X509Certificate cert = (X509Certificate)
            cf.generateCertificate(new FileInputStream(f));
        TrustAnchor anchor = new TrustAnchor(cert, null);

        X509CertSelector xs = new X509CertSelector();

        // a non-exist subject which will ruin the builder soon
        xs.setSubject("CN=A, OU=A, O=A, L=A, ST=A, C=A");
        PKIXBuilderParameters pkp =
            new PKIXBuilderParameters(Collections.singleton(anchor), xs);
        cpb.build(pkp);
    } catch(SunCertPathBuilderException e) {
        System.out.println("Got the Exception: ");
        try {
            ObjectOutputStream o =
                new ObjectOutputStream(new ByteArrayOutputStream());
            o.writeObject(e);
            o.close();
        } catch(NotSerializableException e2) {
            System.out.println("Test fail: bug not corrected");
            throw e2;
        }
        System.out.println("Test pass: SCPEE is Serializable");
        return;
    }
    throw new Exception("Test fail: Strange, no SCPEE thrown");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:35,代码来源:SunCertPathBuilderExceptionTest.java


注:本文中的sun.security.provider.certpath.SunCertPathBuilderException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。