SQL Server
SQL Server
Extract XML string from a .p7m byte array (e.g. FATTURA ELETTRONICA, ITALY)
See more Digital Signatures Examples
_LANGUAGE_ example to extract the original XML from a .p7m (Signed-Data PKCS7 Format) provided as a byte array.One use for this example is to extract the original XML from a Fattura Elettronica .p7m signature.
Chilkat SQL Server Downloads
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
DECLARE @sTmp0 nvarchar(4000)
-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
DECLARE @fac int
EXEC @hr = sp_OACreate 'Chilkat.FileAccess', @fac OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
ERROR: Cannot use pbytes in SQL Server examples...
EXEC sp_OAMethod @fac, 'ReadEntireFile', @p7mBytes OUT, 'testData/p7m/fattura_signature.p7m'
EXEC sp_OAGetProperty @fac, 'LastMethodSuccess', @iTmp0 OUT
IF @iTmp0 <> 1
BEGIN
EXEC sp_OAGetProperty @fac, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @fac
RETURN
END
DECLARE @crypt int
EXEC @hr = sp_OACreate 'Chilkat.Crypt2', @crypt OUT
DECLARE @originalXml nvarchar(4000)
EXEC sp_OAMethod @crypt, 'OpaqueVerifyString', @originalXml OUT, @p7mBytes
EXEC sp_OAGetProperty @crypt, 'LastMethodSuccess', @iTmp0 OUT
IF @iTmp0 <> 1
BEGIN
EXEC sp_OAGetProperty @fac, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @fac
EXEC @hr = sp_OADestroy @crypt
RETURN
END
PRINT 'Original XML:'
PRINT @originalXml
PRINT 'Success!'
EXEC @hr = sp_OADestroy @fac
EXEC @hr = sp_OADestroy @crypt
END
GO