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


Java AttributeTypeAndValue类代码示例

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


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

示例1: getNameFromCert

import org.spongycastle.asn1.x500.AttributeTypeAndValue; //导入依赖的package包/类
private @Nullable String getNameFromCert(TrustAnchor rootAuthority) throws PaymentRequestException.PkiVerificationException {
    org.spongycastle.asn1.x500.X500Name name = new X500Name(rootAuthority.getTrustedCert().getSubjectX500Principal().getName());
    String commonName = null, org = null, location = null, country = null;
    for (RDN rdn : name.getRDNs()) {
        AttributeTypeAndValue pair = rdn.getFirst();
        String val = ((ASN1String)pair.getValue()).getString();
        if (pair.getType().equals(RFC4519Style.cn))
            commonName = val;
        else if (pair.getType().equals(RFC4519Style.o))
            org = val;
        else if (pair.getType().equals(RFC4519Style.l))
            location = val;
        else if (pair.getType().equals(RFC4519Style.c))
            country = val;
    }
    if (org != null) {
        return Joiner.on(", ").skipNulls().join(org, location, country);
    } else {
        return commonName;
    }
}
 
开发者ID:HashEngineering,项目名称:megacoinj,代码行数:22,代码来源:PaymentSession.java

示例2: getDisplayNameFromCertificate

import org.spongycastle.asn1.x500.AttributeTypeAndValue; //导入依赖的package包/类
/**
 * Returns either a string that "sums up" the certificate for humans, in a similar manner to what you might see
 * in a web browser, or null if one cannot be extracted. This will typically be the common name (CN) field, but
 * can also be the org (O) field, org+location+country if withLocation is set, or the email
 * address for S/MIME certificates.
 */
@Nullable
public static String getDisplayNameFromCertificate(@Nonnull X509Certificate certificate, boolean withLocation) throws CertificateParsingException {
    X500Name name = new X500Name(certificate.getSubjectX500Principal().getName());
    String commonName = null, org = null, location = null, country = null;
    for (RDN rdn : name.getRDNs()) {
        AttributeTypeAndValue pair = rdn.getFirst();
        String val = ((ASN1String) pair.getValue()).getString();
        ASN1ObjectIdentifier type = pair.getType();
        if (type.equals(RFC4519Style.cn))
            commonName = val;
        else if (type.equals(RFC4519Style.o))
            org = val;
        else if (type.equals(RFC4519Style.l))
            location = val;
        else if (type.equals(RFC4519Style.c))
            country = val;
    }
    final Collection<List<?>> subjectAlternativeNames = certificate.getSubjectAlternativeNames();
    String altName = null;
    if (subjectAlternativeNames != null)
        for (final List<?> subjectAlternativeName : subjectAlternativeNames)
            if ((Integer) subjectAlternativeName.get(0) == 1) // rfc822name
                altName = (String) subjectAlternativeName.get(1);

    if (org != null) {
        return withLocation ? Joiner.on(", ").skipNulls().join(org, location, country) : org;
    } else if (commonName != null) {
        return commonName;
    } else {
        return altName;
    }
}
 
开发者ID:creativechain,项目名称:creacoinj,代码行数:39,代码来源:X509Utils.java

示例3: getDisplayNameFromCertificate

import org.spongycastle.asn1.x500.AttributeTypeAndValue; //导入依赖的package包/类
/**
 * Returns either a string that "sums up" the certificate for humans, in a similar manner to what you might see
 * in a web browser, or null if one cannot be extracted. This will typically be the common name (CN) field, but
 * can also be the org (O) field, org+location+country if withLocation is set, or the email
 * address for S/MIME certificates.
 */
public static @Nullable String getDisplayNameFromCertificate(@Nonnull X509Certificate certificate, boolean withLocation) throws CertificateParsingException {
    X500Name name = new X500Name(certificate.getSubjectX500Principal().getName());
    String commonName = null, org = null, location = null, country = null;
    for (RDN rdn : name.getRDNs()) {
        AttributeTypeAndValue pair = rdn.getFirst();
        String val = ((ASN1String) pair.getValue()).getString();
        ASN1ObjectIdentifier type = pair.getType();
        if (type.equals(RFC4519Style.cn))
            commonName = val;
        else if (type.equals(RFC4519Style.o))
            org = val;
        else if (type.equals(RFC4519Style.l))
            location = val;
        else if (type.equals(RFC4519Style.c))
            country = val;
    }
    final Collection<List<?>> subjectAlternativeNames = certificate.getSubjectAlternativeNames();
    String altName = null;
    if (subjectAlternativeNames != null)
        for (final List<?> subjectAlternativeName : subjectAlternativeNames)
            if ((Integer) subjectAlternativeName.get(0) == 1) // rfc822name
                altName = (String) subjectAlternativeName.get(1);

    if (org != null) {
        return withLocation ? Joiner.on(", ").skipNulls().join(org, location, country) : org;
    } else if (commonName != null) {
        return commonName;
    } else {
        return altName;
    }
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:38,代码来源:X509Utils.java


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