List of usage examples for org.bouncycastle.asn1.x500 AttributeTypeAndValue getInstance
public static AttributeTypeAndValue getInstance(Object o)
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; }