public static String getSerialNumber(String certInput) throws Exception { X509Certificate cert = getCertificateFromPem(certInput); return cert.getSerialNumber().toString(); }
public static String getExpirationDate(String certInput) throws Exception { X509Certificate cert = getCertificateFromPem(certInput); return cert.getNotAfter().toString(); }
public static String getIssuedDate(String certInput) throws Exception { X509Certificate cert = getCertificateFromPem(certInput); return cert.getNotBefore().toString(); }
public static String getIssuer(String certInput) throws Exception { X509Certificate cert = getCertificateFromPem(certInput); return cert.getIssuerX500Principal().getName(); }
public static Integer getKeySize(String certInput) throws Exception { X509Certificate cert = getCertificateFromPem(certInput); PublicKey key = cert.getPublicKey(); if (key instanceof RSAPublicKey) { RSAPublicKey keySpec = (RSAPublicKey) key; return keySpec.getModulus().bitLength(); } return null; }
/** * Obtains the fingerprint of the certificate in the "ab:cd:ef:...:12" format. */ public static String getCertificateFingerprint(String certInput) throws Exception { X509Certificate cert = getCertificateFromPem(certInput); if (cert == null) { return null; } return digest(cert); }
public static String getAlgorithm(String certInput) throws Exception { X509Certificate cert = getCertificateFromPem(certInput); return cert.getSigAlgName(); }
public static List<?> getSubjectAlternativeNames(String certInput) throws Exception { X509Certificate cert = getCertificateFromPem(certInput); Collection<List<?>> names = cert.getSubjectAlternativeNames(); if (names == null) { return null; } List<String> altNames = new ArrayList<>(); Iterator<List<?>> it = names.iterator(); while (it.hasNext()) { List<?> obj = it.next(); // first value is type identifier (IP, DNS, etc), so adding second only altNames.add(obj.get(1).toString()); } return altNames; }
public static String getVersion(String certInput) throws Exception { X509Certificate cert = getCertificateFromPem(certInput); return String.valueOf(cert.getVersion()); }
public static String getCN(String certInput) throws Exception { X509Certificate cert = getCertificateFromPem(certInput); String dn = cert.getSubjectX500Principal().getName(); LdapName ln = new LdapName(dn); for (Rdn rdn : ln.getRdns()) { if (rdn.getType().equalsIgnoreCase("CN")) { return rdn.getValue().toString(); } } return null; }