Sample code for 30+ languages & platforms
Zig

Import a Certificate (.cer file) into a Windows Certificate Store

See more Certificates Examples

Demonstrates how to import a certificate (without private key) into a Windows certificate store.

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();

    const cert = try chilkat.Cert.init();
    defer cert.deinit();

    cert.loadFromFile("qa_data/certs/example.cer") catch {
        std.debug.print("{s}\n", .{try cert.getLastErrorText(alloc)});
        return;
    };

    const cert_store_cu = try chilkat.CertStore.init();
    defer cert_store_cu.deinit();
    const read_only_flag = false;

    // "CurrentUser" and "My" are the exact keywords to select your user account's certificate store.
    cert_store_cu.openWindowsStore("CurrentUser", "My", read_only_flag) catch {
        std.debug.print("Failed to open the CurrentUser/My certificate store for read/write.\n", .{});
        return;
    };

    // Import the certificate into the CurrentUser/My certificate store.
    cert_store_cu.addCertificate(cert) catch {
        std.debug.print("{s}\n", .{try cert_store_cu.getLastErrorText(alloc)});
        return;
    };

    std.debug.print("Imported {s}\n", .{try cert.getSubjectCN(alloc)});
    std.debug.print("Success.\n", .{});
}