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) Sign a Byte Array to Create an Opaque Signature in a Byte ArraySigns data contained in a byte array to produce an opaque signature (also in a byte array). An opaque signature is a PKCS7 signature (also known as CAdES) that embeds the signed data. Also shows how to verify the signature and extract the original data.
-- 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 -- 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 @cert int -- Use "Chilkat_9_5_0.Cert" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Cert', @cert OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END DECLARE @success int EXEC sp_OAMethod @cert, 'LoadPfxFile', @success OUT, 'qa_data/pfx/cert_test123.pfx', 'test123' IF @success = 0 BEGIN EXEC sp_OAGetProperty @cert, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @cert RETURN END DECLARE @fac int -- Use "Chilkat_9_5_0.FileAccess" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.FileAccess', @fac OUT EXEC sp_OAMethod @fac, 'ReadEntireFile', @fileBytes OUT, 'qa_data/pdf/sample.pdf' EXEC sp_OAGetProperty @fac, 'LastMethodSuccess', @iTmp0 OUT IF @iTmp0 <> 1 BEGIN EXEC sp_OAGetProperty @fac, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @cert EXEC @hr = sp_OADestroy @fac 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 EXEC sp_OAMethod @crypt, 'SetSigningCert', @success OUT, @cert -- We can sign any type of file. EXEC sp_OAMethod @crypt, 'OpaqueSignBytes', @sigBytes OUT, @fileBytes EXEC sp_OAGetProperty @crypt, 'LastMethodSuccess', @iTmp0 OUT IF @iTmp0 <> 1 BEGIN EXEC sp_OAGetProperty @crypt, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @cert EXEC @hr = sp_OADestroy @fac EXEC @hr = sp_OADestroy @crypt RETURN END EXEC sp_OAMethod @fac, 'WriteEntireFile', @success OUT, 'qa_output/sample.pdf.p7m', @sigBytes EXEC sp_OAGetProperty @fac, 'LastMethodSuccess', @iTmp0 OUT IF @iTmp0 <> 1 BEGIN EXEC sp_OAGetProperty @fac, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @cert EXEC @hr = sp_OADestroy @fac EXEC @hr = sp_OADestroy @crypt RETURN END -- We can verify the opaque signature and extract the original data like this EXEC sp_OAMethod @crypt, 'OpaqueVerifyBytes', @originalData OUT, @sigBytes EXEC sp_OAGetProperty @crypt, 'LastMethodSuccess', @iTmp0 OUT IF @iTmp0 <> 1 BEGIN EXEC sp_OAGetProperty @crypt, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @cert EXEC @hr = sp_OADestroy @fac EXEC @hr = sp_OADestroy @crypt RETURN END EXEC sp_OAMethod @fac, 'WriteEntireFile', @success OUT, 'qa_output/sample.pdf', @originalData EXEC sp_OAGetProperty @fac, 'LastMethodSuccess', @iTmp0 OUT IF @iTmp0 <> 1 BEGIN EXEC sp_OAGetProperty @fac, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @cert EXEC @hr = sp_OADestroy @fac EXEC @hr = sp_OADestroy @crypt RETURN END PRINT 'Signature is verified and the original data was extracted.' EXEC @hr = sp_OADestroy @cert EXEC @hr = sp_OADestroy @fac EXEC @hr = sp_OADestroy @crypt END GO |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.