Rust
Rust
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 Rust Downloads
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let dsig = chilkat::XmlDSig::new();
let sb_xml = chilkat::StringBuilder::new();
if sb_xml.load_file("c:/aaworkarea/elias/3/face_f09006808443a699d1b.xml", "utf-8").is_err() {
println!("Failed to load XML file.");
return;
}
if dsig.load_signature_sb(&sb_xml).is_err() {
println!("{}", dsig.last_error_text());
return;
}
// Get the KeyInfo XML.
let Ok(xml_key_info) = dsig.get_key_info() else {
println!("{}", dsig.last_error_text());
return;
};
println!("{}", xml_key_info.get_xml().unwrap_or_default());
println!("----");
// 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>
let Ok(cert_base64) = xml_key_info.get_child_content("*:X509Data|*:X509Certificate") else {
println!("No X509Certificate found in the KeyInfo.");
return;
};
// Load a certificate object w/ the base64.
let cert = chilkat::Cert::new();
if cert.load_from_base64(&cert_base64).is_err() {
println!("{}", cert.last_error_text());
return;
}
// Examine the cert..
println!("SubjectDN: {}", cert.subject_dn());
println!("IssuerDN: {}", cert.issuer_dn());
println!("SerialNumber as Decimal: {}", cert.serial_decimal());