How to extract CN from X509Certificate in Java?

 

 

X509Certificate cert = ...;
X500Name x500name = new JcaX509CertificateHolder(cert).getSubject();
RDN cn = x500name.getRDNs(BCStyle.CN)[0];
return IETFUtils.valueToString(cn.getFirst().getValue());

Leave a Reply

Your email address will not be published. Required fields are marked *