SQL Server
SQL Server
Extract a File from a .p7m (PKCS7 Signed-Data)
See more Encryption Examples
_LANGUAGE_ example to extract the original file from a .p7m (Signed-Data PKCS7 Format) The .p7m contains the signed contents of the original file. It can be verified and restored by calling VerifyP7M.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
-- Important: Do not use nvarchar(max). See the warning about using nvarchar(max).
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
DECLARE @crypt int
EXEC @hr = sp_OACreate 'Chilkat.Crypt2', @crypt OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
-- What is a .p7m file?
DECLARE @outputFile nvarchar(4000)
SELECT @outputFile = '/Users/chilkat/testData/pdf/sample.pdf'
DECLARE @inFile nvarchar(4000)
SELECT @inFile = '/Users/chilkat/testData/p7m/sample.pdf.p7m'
-- Verify and restore the original file:
EXEC sp_OAMethod @crypt, 'VerifyP7M', @success OUT, @inFile, @outputFile
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @crypt, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @crypt
RETURN
END
PRINT 'Success!'
EXEC @hr = sp_OADestroy @crypt
END
GO