Zig
Zig
Examine KeyInfo Certificate in XML Signature
See more XML Digital Signatures Examples
This example loads signed XML and gets the signing certificate, assuming the certificate is contained in X509Certificate within the KeyInfo.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 dsig = try chilkat.XmlDSig.init();
defer dsig.deinit();
const sb_xml = try chilkat.StringBuilder.init();
defer sb_xml.deinit();
sb_xml.loadFile("c:/aaworkarea/elias/3/face_f09006808443a699d1b.xml", "utf-8") catch {
std.debug.print("Failed to load XML file.\n", .{});
return;
};
dsig.loadSignatureSb(sb_xml) catch {
std.debug.print("{s}\n", .{try dsig.getLastErrorText(alloc)});
return;
};
// Get the KeyInfo XML.
const xml_key_info = dsig.getKeyInfo() catch {
std.debug.print("{s}\n", .{try dsig.getLastErrorText(alloc)});
return;
};
defer xml_key_info.deinit();
std.debug.print("{s}\n", .{try xml_key_info.getXml(alloc)});
std.debug.print("----\n", .{});
// Assuming the X509Certificate is in the KeyInfo, it will look like this:
// <ds:KeyInfo Id="...">
// <ds:KeyValue>
// ...
// <ds:X509Data>
// <ds:X509Certificate>MIIHAz...</ds:X509Certificate>
// </ds:X509Data>
// </ds:KeyInfo>
const cert_base64 = xml_key_info.getChildContent(alloc, "*:X509Data|*:X509Certificate") catch {
std.debug.print("No X509Certificate found in the KeyInfo.\n", .{});
return;
};
// Load a certificate object w/ the base64.
const cert = try chilkat.Cert.init();
defer cert.deinit();
cert.loadFromBase64(cert_base64) catch {
std.debug.print("{s}\n", .{try cert.getLastErrorText(alloc)});
return;
};
// Examine the cert..
std.debug.print("SubjectDN: {s}\n", .{try cert.getSubjectDN(alloc)});
std.debug.print("IssuerDN: {s}\n", .{try cert.getIssuerDN(alloc)});
std.debug.print("SerialNumber as Decimal: {s}\n", .{try cert.getSerialDecimal(alloc)});
}