Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Unicode C) 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 <C_CkXmlDSigW.h> #include <C_CkStringBuilderW.h> #include <C_CkXmlW.h> #include <C_CkCertW.h> void ChilkatSample(void) { HCkXmlDSigW dsig; HCkStringBuilderW sbXml; BOOL success; HCkXmlW xmlKeyInfo; const wchar_t *certBase64; HCkCertW cert; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. dsig = CkXmlDSigW_Create(); sbXml = CkStringBuilderW_Create(); success = CkStringBuilderW_LoadFile(sbXml,L"c:/aaworkarea/elias/3/face_f09006808443a699d1b.xml",L"utf-8"); if (success != TRUE) { wprintf(L"Failed to load XML file.\n"); CkXmlDSigW_Dispose(dsig); CkStringBuilderW_Dispose(sbXml); return; } success = CkXmlDSigW_LoadSignatureSb(dsig,sbXml); if (success != TRUE) { wprintf(L"%s\n",CkXmlDSigW_lastErrorText(dsig)); CkXmlDSigW_Dispose(dsig); CkStringBuilderW_Dispose(sbXml); return; } // Get the KeyInfo XML. xmlKeyInfo = CkXmlDSigW_GetKeyInfo(dsig); if (CkXmlDSigW_getLastMethodSuccess(dsig) != TRUE) { wprintf(L"%s\n",CkXmlDSigW_lastErrorText(dsig)); CkXmlDSigW_Dispose(dsig); CkStringBuilderW_Dispose(sbXml); return; } wprintf(L"%s\n",CkXmlW_getXml(xmlKeyInfo)); wprintf(L"----\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> certBase64 = CkXmlW_getChildContent(xmlKeyInfo,L"*:X509Data|*:X509Certificate"); if (CkXmlW_getLastMethodSuccess(xmlKeyInfo) != TRUE) { wprintf(L"No X509Certificate found in the KeyInfo.\n"); CkXmlDSigW_Dispose(dsig); CkStringBuilderW_Dispose(sbXml); return; } // Load a certificate object w/ the base64. cert = CkCertW_Create(); success = CkCertW_LoadFromBase64(cert,certBase64); if (success != TRUE) { wprintf(L"%s\n",CkCertW_lastErrorText(cert)); CkXmlDSigW_Dispose(dsig); CkStringBuilderW_Dispose(sbXml); CkCertW_Dispose(cert); return; } // Examine the cert.. wprintf(L"SubjectDN: %s\n",CkCertW_subjectDN(cert)); wprintf(L"IssuerDN: %s\n",CkCertW_issuerDN(cert)); wprintf(L"SerialNumber as Decimal: %s\n",CkCertW_serialDecimal(cert)); CkXmlW_Dispose(xmlKeyInfo); CkXmlDSigW_Dispose(dsig); CkStringBuilderW_Dispose(sbXml); CkCertW_Dispose(cert); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.