Java
Chilkat2 Java
Find Certificate by Subject O (Organization)
See more Cert Store Examples
Demonstrates how to find a certificate having the specified subject organization.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 Subject O = "ICP-Brasil".
JsonObject json = new JsonObject();
String organization = "ICP-Brasil";
json.updateString("O", organization);
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.");
}
}
}