Sample code for 30+ languages & platforms
Java

Find Certificate by Serial Number

See more Cert Store Examples

Demonstrates how to find a certificate having the specified hexadecimal serial number.

Note: Requires Chilkat v10.1.2 or later.

Chilkat Java Downloads

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

public class ChilkatExample {

    public static void main(String[] args) {
        CertStore certStore = new CertStore();

        // This example will search the certs on connected USB tokens and smartcards.
        String argNotUsed = "";
        try {
            certStore.openSmartcard(argNotUsed);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        // Find the certificate having a serial number = "48FC93B46055948D36A7C98A89D69416".
        String hexSerial = "48FC93B46055948D36A7C98A89D69416";
        JsonObject json = new JsonObject();
        json.updateString("serial", hexSerial);

        Cert cert = new Cert();
        try {
            certStore.findCert(json, cert);
            // Show the serial number and subject CN
            System.out.println("Found: " + cert.getSerialNumber() + ", " + cert.getSubjectCN());
        } catch (ChilkatException e) {
            System.out.println("Not found.");
        }
    }
}