Zig
Zig
DSA Get Key as XML
Gets the DSA key in XML format.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const dsa = try chilkat.Dsa.init();
defer dsa.deinit();
// Generate a new 2048 bit DSA key.
dsa.genKey(2048) catch {
std.debug.print("{s}\n", .{try dsa.getLastErrorText(alloc)});
return;
};
// Get the public key as XML
var b_public_only: bool = true;
var xml_str: [:0]const u8 = try dsa.toXml(alloc, b_public_only);
std.debug.print("{s}\n", .{xml_str});
// Sample output.
// <DSAKeyValue>
// <P>wBYOKu...2eoXw==</P>
// <Q>1taJI7...kV2/9c=</Q>
// <G>qjfbTi...eB1+g==</G>
// <Y>t3tz...NqjsPEg==</Y>
// </DSAKeyValue>
// Get the private key as XML.
b_public_only = false;
xml_str = try dsa.toXml(alloc, b_public_only);
std.debug.print("{s}\n", .{xml_str});
// Sample output.
// <DSAKeyValue>
// <P>wBYOKu...2eoXw==</P>
// <Q>1taJI7...kV2/9c=</Q>
// <G>qjfbTi...eB1+g==</G>
// <Y>t3tz...NqjsPEg==</Y>
// <X>lm9F...XzuVO+qU=</X>
// </DSAKeyValue>
}