Chilkat HOME Android™ Classic ASP C C++ C# Mono C# .NET Core C# C# UWP/WinRT DataFlex Delphi ActiveX Delphi DLL Visual FoxPro Java Lianja MFC Objective-C Perl PHP ActiveX PHP Extension PowerBuilder PowerShell PureBasic CkPython Chilkat2-Python Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ Visual Basic 6.0 VB.NET VB.NET UWP/WinRT VBScript Xojo Plugin Node.js Excel Go
(MFC) Examine KeyInfo Certificate in XML SignatureThis example loads signed XML and gets the signing certificate, assuming the certificate is contained in X509Certificate within the KeyInfo.
#include <CkXmlDSig.h> #include <CkStringBuilder.h> #include <CkXml.h> #include <CkCert.h> void ChilkatSample(void) { CkString strOut; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. CkXmlDSig dsig; CkStringBuilder sbXml; bool success = sbXml.LoadFile("c:/aaworkarea/elias/3/face_f09006808443a699d1b.xml","utf-8"); if (success != true) { strOut.append("Failed to load XML file."); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } success = dsig.LoadSignatureSb(sbXml); if (success != true) { strOut.append(dsig.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } // Get the KeyInfo XML. CkXml *xmlKeyInfo = dsig.GetKeyInfo(); if (dsig.get_LastMethodSuccess() != true) { strOut.append(dsig.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } strOut.append(xmlKeyInfo->getXml()); strOut.append("\r\n"); strOut.append("----"); strOut.append("\r\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 char *certBase64 = xmlKeyInfo->getChildContent("*:X509Data|*:X509Certificate"); if (xmlKeyInfo->get_LastMethodSuccess() != true) { strOut.append("No X509Certificate found in the KeyInfo."); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } // Load a certificate object w/ the base64. CkCert cert; success = cert.LoadFromBase64(certBase64); if (success != true) { strOut.append(cert.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } // Examine the cert.. strOut.append("SubjectDN: "); strOut.append(cert.subjectDN()); strOut.append("\r\n"); strOut.append("IssuerDN: "); strOut.append(cert.issuerDN()); strOut.append("\r\n"); strOut.append("SerialNumber as Decimal: "); strOut.append(cert.serialDecimal()); strOut.append("\r\n"); delete xmlKeyInfo; SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); } |
© 2000-2022 Chilkat Software, Inc. All Rights Reserved.