Sample code for 30+ languages & platforms
Zig

Load Certificate from .cer and Private Key from .pem

See more Certificates Examples

Load a certificate from a .cer and its associated private key from a .pem.

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("C:/certs_and_keys/Certificate.cer") catch {
        std.debug.print("{s}\n", .{try cert.getLastErrorText(alloc)});
        return;
    };

    const sb_pem = try chilkat.StringBuilder.init();
    defer sb_pem.deinit();
    sb_pem.loadFile("C:/certs_and_keys/PrivateKey.pem", "utf-8") catch {
        std.debug.print("Failed to load private key PEM\n", .{});
        return;
    };

    cert.setPrivateKeyPem(try sb_pem.getAsString(alloc)) catch {
        std.debug.print("{s}\n", .{try cert.getLastErrorText(alloc)});
        return;
    };

    std.debug.print("The certificate and associated private key are now loaded and ready for signing.\n", .{});
}