Sample code for 30+ languages & platforms
Rust

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 Rust Downloads

Rust

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

// This example will search the certs on connected USB tokens and smartcards.
let arg_not_used = String::new();
if cert_store.open_smartcard(&arg_not_used).is_err() {
    println!("{}", cert_store.last_error_text());
    return;
}

// Find the certificate having a serial number = "48FC93B46055948D36A7C98A89D69416".
let hex_serial = "48FC93B46055948D36A7C98A89D69416".to_string();
let json = chilkat::JsonObject::new();
let _ = json.update_string("serial", &hex_serial);

let cert = chilkat::Cert::new();
if cert_store.find_cert(&json, &cert).is_ok() {
    // Show the serial number and subject CN
    println!("Found: {}, {}", cert.serial_number(), cert.subject_cn());
} else {
    println!("Not found.");
}