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


Java DNSName类代码示例

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


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

示例1: testSubjectAltName

import sun.security.x509.DNSName; //导入依赖的package包/类
private void testSubjectAltName() throws IOException {
    System.out.println("X.509 Certificate Match on subjectAltName");
    // bad match
    X509CertSelector selector = new X509CertSelector();
    GeneralNameInterface dnsName = new DNSName("foo.com");
    DerOutputStream tmp = new DerOutputStream();
    dnsName.encode(tmp);
    selector.addSubjectAlternativeName(2, tmp.toByteArray());
    checkMatch(selector, cert, false);

    // good match
    DerInputStream in = new DerInputStream(cert.getExtensionValue("2.5.29.17"));
    byte[] encoded = in.getOctetString();
    SubjectAlternativeNameExtension ext = new SubjectAlternativeNameExtension(false, encoded);
    GeneralNames names = (GeneralNames) ext.get(SubjectAlternativeNameExtension.SUBJECT_NAME);
    GeneralName name = (GeneralName) names.get(0);
    selector.setSubjectAlternativeNames(null);
    DerOutputStream tmp2 = new DerOutputStream();
    name.getName().encode(tmp2);
    selector.addSubjectAlternativeName(name.getType(), tmp2.toByteArray());
    checkMatch(selector, cert, true);

    // good match 2 (matches at least one)
    selector.setMatchAllSubjectAltNames(false);
    selector.addSubjectAlternativeName(2, "foo.com");
    checkMatch(selector, cert, true);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:28,代码来源:X509CertSelectorTest.java

示例2: addSubjectAltNameDNSExt

import sun.security.x509.DNSName; //导入依赖的package包/类
/**
 * Helper method to add DNSName types for the SAN extension
 *
 * @param dnsNames A {@code List} of names to add as DNSName types
 *
 * @throws IOException if an encoding error occurs.
 */
public void addSubjectAltNameDNSExt(List<String> dnsNames) throws IOException {
    if (!dnsNames.isEmpty()) {
        GeneralNames gNames = new GeneralNames();
        for (String name : dnsNames) {
            gNames.add(new GeneralName(new DNSName(name)));
        }
        addExtension(new SubjectAlternativeNameExtension(false,
                gNames));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:CertificateBuilder.java


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