Reputation: 1050
Okay this is probably a very stupid question but I'm using bouncycastle to parse issuer RDNS from a X509Certificate in the following way:
X500Name x500name = new JcaX509CertificateHolder(certificate).getIssuer();
RDN[] rdns = x500name.getRDNs();
for (int i = 0; i < rdns.length; ++i)
String readableString = IETFUtils.valueToString(rdns[i].getFirst().getType())
...
... but all I get is some ASN1 OIDs.
So is there a way to convert ASN1ObjectIdentifier to a readable String like "CN", "OU" etc... instead of OIDs?
Thanks!
Upvotes: 4
Views: 3158
Reputation: 21
Using
X500Name x500name = new JcaX509CertificateHolder(certificate).getSubject();
will give you more detailed output than getIssuer()
.
Upvotes: 0
Reputation: 8405
Take a look at org.bouncycastle.asn1.x500.X500NameStyle and its implementations.
X500NameStyle x500NameStyle = RFC4519Style.INSTANCE;
X500Name x500name = new JcaX509CertificateHolder( certificate ).getIssuer();
RDN[] rdns = x500name.getRDNs();
for ( RDN rdn : rdns ) {
for ( AttributeTypeAndValue attribute : rdn.getTypesAndValues() ) {
System.out.printf( "%s (%s) = %s%n",
x500NameStyle.oidToDisplayName( attribute.getType() ),
attribute.getType(),
attribute.getValue()
);
}
}
Upvotes: 6