Dart
Dart
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 Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
final dsig = CkXmlDSig();
final sbXml = CkStringBuilder();
try {
sbXml.loadFile('c:/aaworkarea/elias/3/face_f09006808443a699d1b.xml', 'utf-8');
} on ChilkatException {
print('Failed to load XML file.');
return;
}
try {
dsig.loadSignatureSb(sbXml);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// Get the KeyInfo XML.
final CkXml xmlKeyInfo;
try {
xmlKeyInfo = dsig.getKeyInfo();
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
print(xmlKeyInfo.getXml());
print('----');
// 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>
final String certBase64;
try {
certBase64 = xmlKeyInfo.getChildContent('*:X509Data|*:X509Certificate');
} on ChilkatException {
print('No X509Certificate found in the KeyInfo.');
return;
}
// Load a certificate object w/ the base64.
final cert = CkCert();
try {
cert.loadFromBase64(certBase64);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// Examine the cert..
print('SubjectDN: ${cert.subjectDN}');
print('IssuerDN: ${cert.issuerDN}');
print('SerialNumber as Decimal: ${cert.serialDecimal}');
}