Unicode C
Unicode C
Extract XML from FatturaPA .p7m
See more Digital Signatures Examples
Demonstrates how to verify the signature and extract the XML from a FatturaPA .p7m file.Chilkat Unicode C Downloads
#include <C_CkBinDataW.h>
#include <C_CkCrypt2W.h>
#include <C_CkXmlW.h>
void ChilkatSample(void)
{
BOOL success;
HCkBinDataW bd;
HCkCrypt2W crypt;
BOOL bVerified;
HCkXmlW xml;
success = FALSE;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
bd = CkBinDataW_Create();
success = CkBinDataW_LoadFile(bd,L"qa_data/p7m/IT01879020517_abc.xml.p7m");
if (success != TRUE) {
wprintf(L"Failed to load the .p7m file\n");
CkBinDataW_Dispose(bd);
return;
}
crypt = CkCrypt2W_Create();
// Verify and extrct the payload contained within the .p7m.
// In this case, the payload is the FatturaPA XML.
// If successful, the resulting bd will contain only the XML.
bVerified = CkCrypt2W_OpaqueVerifyBd(crypt,bd);
if (bVerified != TRUE) {
wprintf(L"%s\n",CkCrypt2W_lastErrorText(crypt));
wprintf(L"Failed to extract and verify.\n");
CkBinDataW_Dispose(bd);
CkCrypt2W_Dispose(crypt);
return;
}
// Save the XML to a file.
CkBinDataW_WriteFile(bd,L"qa_output/zIT01879020517_abc.xml");
// Alternatively, load into an XML object and emit.
xml = CkXmlW_Create();
CkXmlW_LoadXml(xml,CkBinDataW_getString(bd,L"utf-8"));
wprintf(L"%s\n",CkXmlW_getXml(xml));
CkBinDataW_Dispose(bd);
CkCrypt2W_Dispose(crypt);
CkXmlW_Dispose(xml);
}