The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > java.security.cert  [9 examples] > Certificates  [5 examples]

e227. Getting the Subject and Issuer Distinguished Names of an X509 Certificate

This example lists the subject and issuer distinguished names of the certificates in a keystore. To load a keystore, see e208 Listing the Aliases in a Key Store.
    try {
        // List the aliases
        Enumeration enum = keystore.aliases();
        for (; enum.hasMoreElements(); ) {
            String alias = (String)enum.nextElement();
    
            java.security.cert.Certificate cert = keystore.getCertificate(alias);
            if (cert instanceof X509Certificate) {
                X509Certificate x509cert = (X509Certificate)cert;
    
                // Get subject
                Principal principal = x509cert.getSubjectDN();
                String subjectDn = principal.getName();
    
                // Get issuer
                principal = x509cert.getIssuerDN();
                String issuerDn = principal.getName();
            }
        }
    } catch (KeyStoreException e) {
    }

 Related Examples
e223. Creating a New Key Pair and Self-Signed Certificate Using keytool
e224. Exporting a Certificate to a File
e225. Importing a Certificate from a File
e226. Listing All Available Certificate Formats

See also: Certification Paths   


© 2002 Addison-Wesley.