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!
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()
);
}
}
Using
X500Name x500name = new JcaX509CertificateHolder(certificate).();
will give you more detailed output than getIssuer()
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.