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
(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_CkXmlDSig.h> #include <C_CkStringBuilder.h> #include <C_CkXml.h> #include <C_CkCert.h> void ChilkatSample(void) { HCkXmlDSig dsig; HCkStringBuilder sbXml; BOOL success; HCkXml xmlKeyInfo; const char *certBase64; HCkCert cert; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. dsig = CkXmlDSig_Create(); sbXml = CkStringBuilder_Create(); success = CkStringBuilder_LoadFile(sbXml,"c:/aaworkarea/elias/3/face_f09006808443a699d1b.xml","utf-8"); if (success != TRUE) { printf("Failed to load XML file.\n"); CkXmlDSig_Dispose(dsig); CkStringBuilder_Dispose(sbXml); return; } success = CkXmlDSig_LoadSignatureSb(dsig,sbXml); if (success != TRUE) { printf("%s\n",CkXmlDSig_lastErrorText(dsig)); CkXmlDSig_Dispose(dsig); CkStringBuilder_Dispose(sbXml); return; } // Get the KeyInfo XML. xmlKeyInfo = CkXmlDSig_GetKeyInfo(dsig); if (CkXmlDSig_getLastMethodSuccess(dsig) != TRUE) { printf("%s\n",CkXmlDSig_lastErrorText(dsig)); CkXmlDSig_Dispose(dsig); CkStringBuilder_Dispose(sbXml); return; } printf("%s\n",CkXml_getXml(xmlKeyInfo)); printf("----\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 = CkXml_getChildContent(xmlKeyInfo,"*:X509Data|*:X509Certificate"); if (CkXml_getLastMethodSuccess(xmlKeyInfo) != TRUE) { printf("No X509Certificate found in the KeyInfo.\n"); CkXmlDSig_Dispose(dsig); CkStringBuilder_Dispose(sbXml); return; } // Load a certificate object w/ the base64. cert = CkCert_Create(); success = CkCert_LoadFromBase64(cert,certBase64); if (success != TRUE) { printf("%s\n",CkCert_lastErrorText(cert)); CkXmlDSig_Dispose(dsig); CkStringBuilder_Dispose(sbXml); CkCert_Dispose(cert); return; } // Examine the cert.. printf("SubjectDN: %s\n",CkCert_subjectDN(cert)); printf("IssuerDN: %s\n",CkCert_issuerDN(cert)); printf("SerialNumber as Decimal: %s\n",CkCert_serialDecimal(cert)); CkXml_Dispose(xmlKeyInfo); CkXmlDSig_Dispose(dsig); CkStringBuilder_Dispose(sbXml); CkCert_Dispose(cert); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.