本文整理汇总了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");
}