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

List Certificates in the Current User Certificate Store (Windows Only)

See more Certificates Examples

This is a Windows-only example to list the certificates in the current-user certificate store (located in the Windows Registry).

Chilkat Zig Downloads

Zig
const std = @import("std");
const chilkat = @import("chilkat");

pub fn main(init: std.process.Init) !void {
    const alloc = init.arena.allocator();

    // This is a Windows-only example because it lists the certificates
    // stored in the Windows Current User Certificate Store located in the
    // Windows Registry.

    const cert_store = try chilkat.CertStore.init();
    defer cert_store.deinit();

    const read_only = true;
    cert_store.openCurrentUserStore(read_only) catch {
        std.debug.print("{s}\n", .{try cert_store.getLastErrorText(alloc)});
        return;
    };

    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("DN = {s}\n", .{try cert.getSubjectDN(alloc)});
        std.debug.print("Email = {s}\n", .{try cert.getSubjectE(alloc)});
        i = i + 1;
    }
}