Zig
Zig
ZATCA Load Certificate and Private Key from PEM Files
See more ZATCA Examples
Demonstrates how to load a certificate and private key from a pair of PEM files.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// The LoadFromFile method will automatically detect the file format..
const cert = try chilkat.Cert.init();
defer cert.deinit();
cert.loadFromFile("qa_data/zatca/cert.pem") catch {
std.debug.print("{s}\n", .{try cert.getLastErrorText(alloc)});
return;
};
std.debug.print("{s}\n", .{try cert.getSubjectCN(alloc)});
// Load the private key.
const priv_key = try chilkat.PrivateKey.init();
defer priv_key.deinit();
priv_key.loadPemFile("qa_data/zatca/ec-secp256k1-priv-key.pem") catch {
std.debug.print("{s}\n", .{try priv_key.getLastErrorText(alloc)});
return;
};
std.debug.print("Key Type: {s}\n", .{try priv_key.getKeyType(alloc)});
// Associate the private key with the certificate.
cert.setPrivateKey(priv_key) catch {
std.debug.print("{s}\n", .{try cert.getLastErrorText(alloc)});
return;
};
std.debug.print("Success.\n", .{});
}