Java
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
import com.chilkatsoft.*;
public class ChilkatExample {
static {
try {
System.loadLibrary("chilkat");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public static void main(String argv[])
{
boolean success = false;
CkCertStore certStore = new CkCertStore();
// This example will search the certs on connected USB tokens and smartcards.
String argNotUsed = "";
success = certStore.OpenSmartcard(argNotUsed);
if (success == false) {
System.out.println(certStore.lastErrorText());
return;
}
// Find the certificate having a serial number = "48FC93B46055948D36A7C98A89D69416".
String hexSerial = "48FC93B46055948D36A7C98A89D69416";
CkJsonObject json = new CkJsonObject();
json.UpdateString("serial",hexSerial);
CkCert cert = new CkCert();
success = certStore.FindCert(json,cert);
if (success == true) {
// Show the serial number and subject CN
System.out.println("Found: " + cert.serialNumber() + ", " + cert.subjectCN());
}
else {
System.out.println("Not found.");
}
}
}