React Native
React Native
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 React Native Downloads
import { Cert, StringBuilder, Xml, XmlDSig } from '@chilkat/react-native'
function chilkatExample() {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const dsig = new XmlDSig();
const sbXml = new StringBuilder();
try {
sbXml.loadFile('c:/aaworkarea/elias/3/face_f09006808443a699d1b.xml', 'utf-8');
} catch {
console.log('Failed to load XML file.');
return;
}
try {
dsig.loadSignatureSb(sbXml);
} catch {
console.log(dsig.lastErrorText);
return;
}
// Get the KeyInfo XML.
let xmlKeyInfo: Xml;
try {
xmlKeyInfo = dsig.getKeyInfo();
} catch {
console.log(dsig.lastErrorText);
return;
}
console.log(xmlKeyInfo.getXml());
console.log('----');
// 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 certBase64: string;
try {
certBase64 = xmlKeyInfo.getChildContent('*:X509Data|*:X509Certificate');
} catch {
console.log('No X509Certificate found in the KeyInfo.');
return;
}
// Load a certificate object w/ the base64.
const cert = new Cert();
try {
cert.loadFromBase64(certBase64);
} catch {
console.log(cert.lastErrorText);
return;
}
// Examine the cert..
console.log(`SubjectDN: ${cert.subjectDN}`);
console.log(`IssuerDN: ${cert.issuerDN}`);
console.log(`SerialNumber as Decimal: ${cert.serialDecimal}`);
}