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) Get Certificates within XML SignatureDemonstrates how to get the certificates contained within an XML signature.
#include <C_CkStringBuilderW.h> #include <C_CkXmlDSigW.h> #include <C_CkStringArrayW.h> #include <C_CkCertW.h> void ChilkatSample(void) { HCkStringBuilderW sbXml; BOOL success; HCkXmlDSigW dsig; int i; HCkStringArrayW saCerts; HCkCertW cert; BOOL bVerifyReferenceDigests; BOOL bVerified; int j; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. sbXml = CkStringBuilderW_Create(); // Load XML containing one or more signatures. success = CkStringBuilderW_LoadFile(sbXml,L"qa_data/xml_dsig_valid_samples/multipleSigners/sp.pdf.XAdES.xml",L"utf-8"); if (success == FALSE) { wprintf(L"Failed to load the XML file..\n"); CkStringBuilderW_Dispose(sbXml); return; } dsig = CkXmlDSigW_Create(); // First load the XML containing the signatures to be verified. // Note that this particular Signature already contains the RSA public key that will be used // for verification. success = CkXmlDSigW_LoadSignatureSb(dsig,sbXml); if (success != TRUE) { wprintf(L"%s\n",CkXmlDSigW_lastErrorText(dsig)); CkStringBuilderW_Dispose(sbXml); CkXmlDSigW_Dispose(dsig); return; } // For each signature, verify and also get the certificate(s) contained within each Signature. i = 0; saCerts = CkStringArrayW_Create(); cert = CkCertW_Create(); wprintf(L"numSignatures = %d\n",CkXmlDSigW_getNumSignatures(dsig)); while (i < CkXmlDSigW_getNumSignatures(dsig)) { // Select the Nth signature by setting the Selector property. CkXmlDSigW_putSelector(dsig,i); bVerifyReferenceDigests = TRUE; bVerified = CkXmlDSigW_VerifySignature(dsig,bVerifyReferenceDigests); wprintf(L"Signature %d verified = %d\n",i + 1,bVerified); // Get the certificates embedded in this signature. CkStringArrayW_Clear(saCerts); success = CkXmlDSigW_GetCerts(dsig,saCerts); if (success == TRUE) { j = 0; while (j < CkStringArrayW_getCount(saCerts)) { success = CkCertW_LoadFromBase64(cert,CkStringArrayW_getString(saCerts,j)); if (success == TRUE) { wprintf(L" %s\n",CkCertW_subjectDN(cert)); } j = j + 1; } } i = i + 1; } CkStringBuilderW_Dispose(sbXml); CkXmlDSigW_Dispose(dsig); CkStringArrayW_Dispose(saCerts); CkCertW_Dispose(cert); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.