DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Variant vBd
Handle hoBd
Handle hoCrypt
Boolean iBVerified
Handle hoXml
String sTemp1
Move False To iSuccess
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatBinData)) To hoBd
If (Not(IsComObjectCreated(hoBd))) Begin
Send CreateComObject of hoBd
End
Get ComLoadFile Of hoBd "qa_data/p7m/IT01879020517_abc.xml.p7m" To iSuccess
If (iSuccess <> True) Begin
Showln "Failed to load the .p7m file"
Procedure_Return
End
Get Create (RefClass(cComChilkatCrypt2)) To hoCrypt
If (Not(IsComObjectCreated(hoCrypt))) Begin
Send CreateComObject of hoCrypt
End
// 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.
Get pvComObject of hoBd to vBd
Get ComOpaqueVerifyBd Of hoCrypt vBd To iBVerified
If (iBVerified <> True) Begin
Get ComLastErrorText Of hoCrypt To sTemp1
Showln sTemp1
Showln "Failed to extract and verify."
Procedure_Return
End
// Save the XML to a file.
Get ComWriteFile Of hoBd "qa_output/zIT01879020517_abc.xml" To iSuccess
// Alternatively, load into an XML object and emit.
Get Create (RefClass(cComChilkatXml)) To hoXml
If (Not(IsComObjectCreated(hoXml))) Begin
Send CreateComObject of hoXml
End
Get ComGetString Of hoBd "utf-8" To sTemp1
Get ComLoadXml Of hoXml sTemp1 To iSuccess
Get ComGetXml Of hoXml To sTemp1
Showln sTemp1
End_Procedure