Sample code for 30+ languages & platforms
Java

Windows Certificate Stores - Find Certificate by Common Name

See more Certificates Examples

Searches the Windows certificate stores for a certificate that matches the specified common name (CN).

Note: This example requires Chilkat v10.0.0 or greater.

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.Cert;
import com.chilkatsoft.chilkat2.ChilkatException;

public class ChilkatExample {

    public static void main(String[] args) {
        Cert cert = new Cert();
        try {
            cert.loadByCommonName("Chilkat Software, Inc.");
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        System.out.println(cert.getSubjectDN());
        System.out.println("Success.");
    }
}