Zig
Zig
Load PFX/P12 from a Base64 Encoded PFX File
See more PFX/P12 Examples
Demonstrates how to call LoadPfxEncoded.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
const bd = try chilkat.BinData.init();
defer bd.deinit();
bd.loadFile("qa_data/pfx/cert_test123.pfx") catch {
std.debug.print("Failed to load PFX file.\n", .{});
return;
};
// Get the bytes contained in the PFX in base64 format:
const str_base64 = try bd.getEncoded(alloc, "base64");
// The base64 looks like this: "MIIbEAIBAzCCGswGCSqGSIb3DQEHAaCCGr0Eghq5MIIatTCCBg..."
std.debug.print("{s}\n", .{str_base64});
const pfx = try chilkat.Pfx.init();
defer pfx.deinit();
// Load the PFX from the base64 string
const password = "test123";
pfx.loadPfxEncoded(str_base64, "base64", password) catch {
std.debug.print("{s}\n", .{try pfx.getLastErrorText(alloc)});
return;
};
std.debug.print("success\n", .{});
}