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
(SQL Server) Extract XML from FatturaPA .p7mDemonstrates how to verify the signature and extract the XML from a FatturaPA .p7m file.
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls. -- CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int -- Important: Do not use nvarchar(max). See the warning about using nvarchar(max). DECLARE @sTmp0 nvarchar(4000) -- This example requires the Chilkat API to have been previously unlocked. -- See Global Unlock Sample for sample code. DECLARE @bd int -- Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.BinData', @bd OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END DECLARE @success int EXEC sp_OAMethod @bd, 'LoadFile', @success OUT, 'qa_data/p7m/IT01879020517_abc.xml.p7m' IF @success <> 1 BEGIN PRINT 'Failed to load the .p7m file' EXEC @hr = sp_OADestroy @bd RETURN END DECLARE @crypt int -- Use "Chilkat_9_5_0.Crypt2" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Crypt2', @crypt OUT -- 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. DECLARE @bVerified int EXEC sp_OAMethod @crypt, 'OpaqueVerifyBd', @bVerified OUT, @bd IF @bVerified <> 1 BEGIN EXEC sp_OAGetProperty @crypt, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 PRINT 'Failed to extract and verify.' EXEC @hr = sp_OADestroy @bd EXEC @hr = sp_OADestroy @crypt RETURN END -- Save the XML to a file. EXEC sp_OAMethod @bd, 'WriteFile', @success OUT, 'qa_output/zIT01879020517_abc.xml' -- Alternatively, load into an XML object and emit. DECLARE @xml int -- Use "Chilkat_9_5_0.Xml" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Xml', @xml OUT EXEC sp_OAMethod @bd, 'GetString', @sTmp0 OUT, 'utf-8' EXEC sp_OAMethod @xml, 'LoadXml', @success OUT, @sTmp0 EXEC sp_OAMethod @xml, 'GetXml', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @bd EXEC @hr = sp_OADestroy @crypt EXEC @hr = sp_OADestroy @xml END GO |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.