Java
Chilkat2 Java
Find Certificate by SHA1 Thumbprint
See more Cert Store Examples
Demonstrates how to find a certificate having the specified hexadecimal SHA1 thumbprint.Note: Requires Chilkat v10.1.2 or later.
Chilkat Java Downloads
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 opens the Current User certificate store on Windows,
// On MacOS and iOS it opens the default Keychain.
boolean readOnly = false;
try {
certStore.openCurrentUserStore(readOnly);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
// Find the certificate having a specific SHA1 thumbprint.
JsonObject json = new JsonObject();
String hexThumbprint = "767192374BE3C1512D2CB80734926D40E96D6DC2";
json.updateString("thumbprint", hexThumbprint);
Cert cert = new Cert();
try {
certStore.findCert(json, cert);
// Show the full distinguished name of the certificate.
System.out.println("Found: " + cert.getSubjectDN());
} catch (ChilkatException e) {
System.out.println("Not found.");
}
}
}