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 Manifest File to Generate a Passbook .pkpass in MemoryDemonstrates how to create a Passbook .pkpass archive by creating a signature of a manifest file and then zipping to a .pkpass archive in memory
-- 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 requires the Chilkat API to have been previously unlocked. -- See Global Unlock Sample for sample code. -- --------------------------------------------------------------------------------------------- -- This example is the same as Sign Manifest File to Generate a Passbook .pkpass file -- except everything happens in memory (no input files, no output files) -- --------------------------------------------------------------------------------------------- -- First create the manifest.json DECLARE @success int DECLARE @manifest int -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @manifest OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' 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 DECLARE @zip int -- Use "Chilkat_9_5_0.Zip" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Zip', @zip OUT EXEC sp_OAMethod @zip, 'NewZip', @success OUT, 'notUsedAndNeverCreated.zip' EXEC sp_OASetProperty @crypt, 'HashAlgorithm', 'sha1' -- Return hashes as lowercase hex. EXEC sp_OASetProperty @crypt, 'EncodingMode', 'hexlower' DECLARE @digestStr nvarchar(4000) DECLARE @pngData int -- Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.BinData', @pngData OUT -- Assume we load the pngData with bytes for "icon.png" from somewhere, such as a byte array in memory. DECLARE @entry int EXEC sp_OAMethod @zip, 'AppendBd', @entry OUT, 'icon.png', @pngData EXEC @hr = sp_OADestroy @entry EXEC sp_OAMethod @crypt, 'HashBdENC', @digestStr OUT, @pngData EXEC sp_OAMethod @manifest, 'UpdateString', @success OUT, '"icon.png"', @digestStr EXEC sp_OAMethod @pngData, 'Clear', @success OUT -- Assume we load the pngData with bytes for "icon@2x.png" from somewhere... EXEC sp_OAMethod @zip, 'AppendBd', @entry OUT, 'icon@2x.png', @pngData EXEC @hr = sp_OADestroy @entry EXEC sp_OAMethod @crypt, 'HashBdENC', @digestStr OUT, @pngData EXEC sp_OAMethod @manifest, 'UpdateString', @success OUT, '"icon@2x.png"', @digestStr EXEC sp_OAMethod @pngData, 'Clear', @success OUT -- Assume we load the pngData with bytes for "logo.png" from somewhere... EXEC sp_OAMethod @zip, 'AppendBd', @entry OUT, 'logo.png', @pngData EXEC @hr = sp_OADestroy @entry EXEC sp_OAMethod @crypt, 'HashBdENC', @digestStr OUT, @pngData EXEC sp_OAMethod @manifest, 'UpdateString', @success OUT, '"logo.png"', @digestStr EXEC sp_OAMethod @pngData, 'Clear', @success OUT -- Assume we load the pngData with bytes for "logo@2x.png" from somewhere... EXEC sp_OAMethod @zip, 'AppendBd', @entry OUT, 'logo@2x.png', @pngData EXEC @hr = sp_OADestroy @entry EXEC sp_OAMethod @crypt, 'HashBdENC', @digestStr OUT, @pngData EXEC sp_OAMethod @manifest, 'UpdateString', @success OUT, '"logo@2x.png"', @digestStr DECLARE @passJson nvarchar(4000) SELECT @passJson = '{ .... }' -- Contains the contents of pass.json EXEC sp_OAMethod @zip, 'AppendString', @entry OUT, 'pass.json', @passJson EXEC @hr = sp_OADestroy @entry EXEC sp_OAMethod @crypt, 'HashStringENC', @digestStr OUT, @passJson EXEC sp_OAMethod @manifest, 'UpdateString', @success OUT, '"pass.json"', @digestStr EXEC sp_OAMethod @manifest, 'Emit', @sTmp0 OUT EXEC sp_OAMethod @zip, 'AppendString', @entry OUT, 'manifest.json', @sTmp0 EXEC @hr = sp_OADestroy @entry -- Make sure we have the Apple WWDR intermediate certificate available for -- the cert chain in the signature. DECLARE @certVault int -- Use "Chilkat_9_5_0.XmlCertVault" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.XmlCertVault', @certVault OUT DECLARE @appleWwdrCert int -- Use "Chilkat_9_5_0.Cert" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Cert', @appleWwdrCert OUT EXEC sp_OAMethod @appleWwdrCert, 'LoadByCommonName', @success OUT, 'Apple Worldwide Developer Relations Certification Authority' IF @success <> 1 BEGIN PRINT 'The Apple WWDR intermediate certificate is not installed.' PRINT 'It is available at https://developer.apple.com/certificationauthority/AppleWWDRCA.cer' PRINT 'You may alternatively load the .cer like this...' EXEC sp_OAMethod @appleWwdrCert, 'LoadFromFile', @success OUT, 'qa_data/certs/AppleWWDRCA.cer' IF @success <> 1 BEGIN EXEC sp_OAGetProperty @appleWwdrCert, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @manifest EXEC @hr = sp_OADestroy @crypt EXEC @hr = sp_OADestroy @zip EXEC @hr = sp_OADestroy @pngData EXEC @hr = sp_OADestroy @certVault EXEC @hr = sp_OADestroy @appleWwdrCert RETURN END END EXEC sp_OAMethod @certVault, 'AddCert', @success OUT, @appleWwdrCert EXEC sp_OAMethod @crypt, 'UseCertVault', @success OUT, @certVault -- Use a digital certificate and private key from a PFX DECLARE @bdPfx int -- Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.BinData', @bdPfx OUT -- Assume we loaded a PFX into bdPfx.... DECLARE @pfxPassword nvarchar(4000) SELECT @pfxPassword = 'test123' DECLARE @cert int -- Use "Chilkat_9_5_0.Cert" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Cert', @cert OUT EXEC sp_OAMethod @cert, 'LoadPfxBd', @success OUT, @bdPfx, @pfxPassword IF @success <> 1 BEGIN EXEC sp_OAGetProperty @cert, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @manifest EXEC @hr = sp_OADestroy @crypt EXEC @hr = sp_OADestroy @zip EXEC @hr = sp_OADestroy @pngData EXEC @hr = sp_OADestroy @certVault EXEC @hr = sp_OADestroy @appleWwdrCert EXEC @hr = sp_OADestroy @bdPfx EXEC @hr = sp_OADestroy @cert RETURN END -- Provide the signing cert (with associated private key). EXEC sp_OAMethod @crypt, 'SetSigningCert', @success OUT, @cert IF @success <> 1 BEGIN EXEC sp_OAGetProperty @crypt, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @manifest EXEC @hr = sp_OADestroy @crypt EXEC @hr = sp_OADestroy @zip EXEC @hr = sp_OADestroy @pngData EXEC @hr = sp_OADestroy @certVault EXEC @hr = sp_OADestroy @appleWwdrCert EXEC @hr = sp_OADestroy @bdPfx EXEC @hr = sp_OADestroy @cert RETURN END -- Specify the signed attributes to be included. -- (These attributes appear to not be necessary, but we're including -- them just in case they become necessary in the future.) DECLARE @jsonSignedAttrs int -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jsonSignedAttrs OUT EXEC sp_OAMethod @jsonSignedAttrs, 'UpdateInt', @success OUT, 'contentType', 1 EXEC sp_OAMethod @jsonSignedAttrs, 'UpdateInt', @success OUT, 'signingTime', 1 EXEC sp_OAMethod @jsonSignedAttrs, 'Emit', @sTmp0 OUT EXEC sp_OASetProperty @crypt, 'SigningAttributes', @sTmp0 -- Sign the manifest JSON to produce a signature EXEC sp_OASetProperty @crypt, 'EncodingMode', 'base64' DECLARE @sig nvarchar(4000) EXEC sp_OAMethod @manifest, 'Emit', @sTmp0 OUT EXEC sp_OAMethod @crypt, 'SignStringENC', @sig OUT, @sTmp0 DECLARE @bdSig int -- Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.BinData', @bdSig OUT EXEC sp_OAMethod @bdSig, 'AppendEncoded', @success OUT, @sig, 'base64' EXEC sp_OAMethod @zip, 'AppendBd', @entry OUT, 'signature', @bdSig EXEC @hr = sp_OADestroy @entry -- --------------------------------------------------------------------------------------------- -- Note: Chilkat also has the capability to do everything in-memory (no files would be involved). -- If this is of interest, please send email to support@chilkatsoft.com -- --------------------------------------------------------------------------------------------- -- Create the .pkipass archive (which is a .zip archive containing the required files). -- the .zip is written to bdZip DECLARE @bdZip int -- Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.BinData', @bdZip OUT EXEC sp_OAMethod @zip, 'WriteBd', @success OUT, @bdZip IF @success <> 1 BEGIN EXEC sp_OAGetProperty @zip, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @manifest EXEC @hr = sp_OADestroy @crypt EXEC @hr = sp_OADestroy @zip EXEC @hr = sp_OADestroy @pngData EXEC @hr = sp_OADestroy @certVault EXEC @hr = sp_OADestroy @appleWwdrCert EXEC @hr = sp_OADestroy @bdPfx EXEC @hr = sp_OADestroy @cert EXEC @hr = sp_OADestroy @jsonSignedAttrs EXEC @hr = sp_OADestroy @bdSig EXEC @hr = sp_OADestroy @bdZip RETURN END PRINT 'Success.' EXEC @hr = sp_OADestroy @manifest EXEC @hr = sp_OADestroy @crypt EXEC @hr = sp_OADestroy @zip EXEC @hr = sp_OADestroy @pngData EXEC @hr = sp_OADestroy @certVault EXEC @hr = sp_OADestroy @appleWwdrCert EXEC @hr = sp_OADestroy @bdPfx EXEC @hr = sp_OADestroy @cert EXEC @hr = sp_OADestroy @jsonSignedAttrs EXEC @hr = sp_OADestroy @bdSig EXEC @hr = sp_OADestroy @bdZip END GO |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.