Sample code for 30+ languages & platforms
Rust

Find Certificate by Subject CN (Common Name)

See more Cert Store Examples

Demonstrates how to find a certificate having the specified subject CN.

Note: Requires Chilkat v10.1.2 or later.

Chilkat Rust Downloads

Rust

let cert_store = chilkat::CertStore::new();

// This opens the Current User certificate store on Windows,
// On MacOS and iOS it opens the default Keychain.
let read_only = false;
if cert_store.open_current_user_store(read_only).is_err() {
    println!("{}", cert_store.last_error_text());
    return;
}

// Find the certificate having a Subject CN = "Example ABC".
let json = chilkat::JsonObject::new();
let _ = json.update_string("CN", "Example ABC");

let cert = chilkat::Cert::new();
if cert_store.find_cert(&json, &cert).is_ok() {
    // Show the full distinguished name of the certificate.
    println!("Found: {}", cert.subject_dn());
} else {
    println!("Not found.");
}