Zig
Zig
Save a Public Key as an XML File
Demonstrates the Chilkat PublicKey.SaveXmlFile method, which saves the public key as Chilkat XML (the same text as GetXml) to a file. The only argument is the destination path.
Note: The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.
Background: The file-writing form of
GetXml, for interoperating with .NET or XML-signature software that reads XML key values. As a public key it is not sensitive, so the resulting file can be shared. No byte-order mark or extra line-ending changes are added.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// Load a public key to export. LoadFromFile inspects the content, so it accepts DER, PEM, XML,
// JWK, and other supported representations.
const pub_key = try chilkat.PublicKey.init();
defer pub_key.deinit();
pub_key.loadFromFile("qa_data/public.pem") catch {
std.debug.print("{s}\n", .{try pub_key.getLastErrorText(alloc)});
return;
};
// Save the public key as Chilkat XML (the same text as GetXml).
pub_key.saveXmlFile("qa_output/public_key.xml") catch {
std.debug.print("{s}\n", .{try pub_key.getLastErrorText(alloc)});
return;
};
std.debug.print("Saved.\n", .{});
}