Sample code for 30+ languages & platforms
Zig

Apple Keychain - Import Pfx

See more Apple Keychain Examples

Imports the certficates and private keys contained in .pfx (or .p12) to the Apple Keychain. If intermediate CA certs are contained in the PFX, they are also added to the Keychain if needed.

Note: This example requires Chilkat v10.0.0 or greater.

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 pfx_path = "/Users/chilkat/qa_data/pfx/EXAMPLE.pfx";
    const pfx_password = "PASSWORD";

    // Load the PFX file.
    const cert = try chilkat.Cert.init();
    defer cert.deinit();
    cert.loadPfxFile(pfx_path, pfx_password) catch {
        std.debug.print("{s}\n", .{try cert.getLastErrorText(alloc)});
        return;
    };

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

    // Note: On MacOS and iOS, the AddCertificate method adds to the Keychain.
    // There is no need to "open" the Keychain beforehand.
    cert_store.addCertificate(cert) catch {
        std.debug.print("{s}\n", .{try cert_store.getLastErrorText(alloc)});
        return;
    };

    std.debug.print("Success.\n", .{});
}