Zig Requires Chilkat v10.1.2+
Zig
Load PFX/P12 File into Certificate Store Object
Demonstrates how to load a .pfx/.p12 into a certificate store object.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
const cert_store = try chilkat.CertStore.init();
defer cert_store.deinit();
// This only loads the contents of the PFX file into the certStore object.
// It is not importing the PFX into the Windows certificate stores.
const pfx_password = "badssl.com";
cert_store.loadPfxFile("qa_data/pfx/badssl.com-client.p12", pfx_password) catch {
std.debug.print("{s}\n", .{try cert_store.getLastErrorText(alloc)});
return;
};
// Examine each certificate (loaded from the PFX) in this certStore object
const cert = try chilkat.Cert.init();
defer cert.deinit();
const num_certs = cert_store.getNumCertificates();
var i: i32 = 0;
while (i < num_certs) {
cert_store.getCert(i, cert) catch {};
std.debug.print("hasPrivateKey={}, {s}\n", .{ cert.hasPrivateKey(), try cert.getSubjectCN(alloc) });
i = i + 1;
}
}