Example usage for org.bouncycastle.asn1.x500 AttributeTypeAndValue getInstance

List of usage examples for org.bouncycastle.asn1.x500 AttributeTypeAndValue getInstance

Introduction

In this page you can find the example usage for org.bouncycastle.asn1.x500 AttributeTypeAndValue getInstance.

Prototype

public static AttributeTypeAndValue getInstance(Object o) 

Source Link

Usage

From source file:com.foilen.smalltools.crypt.bouncycastle.cert.RSACertificate.java

License:Open Source License

/**
 * Get the certificate's common names.//w w  w.jav  a 2s  .com
 *
 * @return the common names
 */
public Set<String> getCommonNames() {
    AssertTools.assertNotNull(certificateHolder, "The certificate is not set");
    X500Name subject = certificateHolder.getSubject();
    Set<String> commonNames = new HashSet<>();
    for (RDN rdn : subject.getRDNs()) {
        ASN1Primitive primitive = rdn.toASN1Primitive();
        if (primitive instanceof ASN1Set) {
            ASN1Set asn1Set = (ASN1Set) primitive;
            for (int i = 0; i < asn1Set.size(); ++i) {
                AttributeTypeAndValue next = AttributeTypeAndValue.getInstance(asn1Set.getObjectAt(i));
                if (OID_COMMON_NAME.equals(next.getType().toString())) {
                    commonNames.add(next.getValue().toString());
                }
            }
        }
    }
    return commonNames;
}