Sample code for 30+ languages & platforms
Rust Requires Chilkat v10.1.2+

Load PFX (PKCS#12) and List Certificates

See more Certificates Examples

Loads a PFX file (.pfx, .p12) and iterates over the certificates found within.

Chilkat Rust Downloads

Rust

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

let pfx_path = "/Users/chilkat/testData/pfx/chilkat_ssl.pfx".to_string();
let pfx_password = "test".to_string();
if cert_store.load_pfx_file(&pfx_path, &pfx_password).is_err() {
    println!("{}", cert_store.last_error_text());
    return;
}

let num_certs = cert_store.num_certificates();

println!("PFX contains {} certificates", num_certs);

let cert = chilkat::Cert::new();
let mut i = 0;
while i < num_certs {
    let _ = cert_store.get_cert(i, &cert);

    println!("{}: (Common Name) {}", i, cert.subject_cn());
    println!("{}: (Serial Number) {}", i, cert.serial_number());
    println!("{}: (Distinguished Name) {}", i, cert.subject_dn());

    i = i + 1;
}