VBScript
VBScript
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 VBScript Downloads
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)
success = 0
' This example requires the Chilkat API to have been previously unlocked.
' See Global Unlock Sample for sample code.
set bd = CreateObject("Chilkat.BinData")
success = bd.LoadFile("qa_data/p7m/IT01879020517_abc.xml.p7m")
If (success <> 1) Then
outFile.WriteLine("Failed to load the .p7m file")
WScript.Quit
End If
set crypt = CreateObject("Chilkat.Crypt2")
' 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 = crypt.OpaqueVerifyBd(bd)
If (bVerified <> 1) Then
outFile.WriteLine(crypt.LastErrorText)
outFile.WriteLine("Failed to extract and verify.")
WScript.Quit
End If
' Save the XML to a file.
success = bd.WriteFile("qa_output/zIT01879020517_abc.xml")
' Alternatively, load into an XML object and emit.
set xml = CreateObject("Chilkat.Xml")
success = xml.LoadXml(bd.GetString("utf-8"))
outFile.WriteLine(xml.GetXml())
outFile.Close