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
(DataFlex) Sign Manifest File to Generate a Passbook .pkpass fileDemonstrates how to create a Passbook .pkpass archive by creating a signature of a manifest file and then zipping to a .pkpass archive. 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 Note: This example requires Chilkat v9.5.0.75.
Use ChilkatAx-win32.pkg Procedure Test Boolean iSuccess Handle hoManifest Handle hoCrypt Handle hoZip String sFileHash String sFilePath Variant vSbJson Handle hoSbJson String sManifestPath Variant vCert Vault Handle hoCertVault Variant vAppleWwdrCert Handle hoAppleWwdrCert String sPfxPath String sPfxPassword Variant vCert Handle hoCert Handle hoJsonSignedAttrs String sSigPath String sTemp1 // Note: Requires Chilkat v9.5.0.75 or greater. // This requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. // --------------------------------------------------------------------------------------------- // Note: Chilkat also has the capability to do everything in-memory (no files would be involved). // See this example: Sign Manifest File to Generate a Passbook .pkpass in Memory // --------------------------------------------------------------------------------------------- // First create the manifest.json Get Create (RefClass(cComChilkatJsonObject)) To hoManifest If (Not(IsComObjectCreated(hoManifest))) Begin Send CreateComObject of hoManifest End Get Create (RefClass(cComChilkatCrypt2)) To hoCrypt If (Not(IsComObjectCreated(hoCrypt))) Begin Send CreateComObject of hoCrypt End Get Create (RefClass(cComChilkatZip)) To hoZip If (Not(IsComObjectCreated(hoZip))) Begin Send CreateComObject of hoZip End Get ComNewZip Of hoZip "qa_data/p7s/pass-wallet/example.pkpass" To iSuccess // Set the AppendFromDir property to prevent that relative paths from being stored in the .pkpass archive. Set ComAppendFromDir Of hoZip To "qa_data/p7s/pass-wallet/" Set ComHashAlgorithm Of hoCrypt To "sha1" // Return hashes as lowercase hex. Set ComEncodingMode Of hoCrypt To "hexlower" Move "qa_data/p7s/pass-wallet/icon.png" To sFilePath Get ComHashFileENC Of hoCrypt sFilePath To sFileHash Get ComAppendOneFileOrDir Of hoZip "icon.png" False To iSuccess Get ComUpdateString Of hoManifest '"icon.png"' sFileHash To iSuccess Move "qa_data/p7s/pass-wallet/icon@2x.png" To sFilePath Get ComHashFileENC Of hoCrypt sFilePath To sFileHash Get ComAppendOneFileOrDir Of hoZip "icon@2x.png" False To iSuccess Get ComUpdateString Of hoManifest '"icon@2x.png"' sFileHash To iSuccess Move "qa_data/p7s/pass-wallet/logo.png" To sFilePath Get ComHashFileENC Of hoCrypt sFilePath To sFileHash Get ComAppendOneFileOrDir Of hoZip "logo.png" False To iSuccess Get ComUpdateString Of hoManifest '"logo.png"' sFileHash To iSuccess Move "qa_data/p7s/pass-wallet/logo@2x.png" To sFilePath Get ComHashFileENC Of hoCrypt sFilePath To sFileHash Get ComAppendOneFileOrDir Of hoZip "logo@2x.png" False To iSuccess Get ComUpdateString Of hoManifest '"logo@2x.png"' sFileHash To iSuccess Move "qa_data/p7s/pass-wallet/pass.json" To sFilePath Get ComHashFileENC Of hoCrypt sFilePath To sFileHash Get ComAppendOneFileOrDir Of hoZip "pass.json" False To iSuccess Get ComUpdateString Of hoManifest '"pass.json"' sFileHash To iSuccess Get Create (RefClass(cComChilkatStringBuilder)) To hoSbJson If (Not(IsComObjectCreated(hoSbJson))) Begin Send CreateComObject of hoSbJson End Get pvComObject of hoSbJson to vSbJson Get ComEmitSb Of hoManifest vSbJson To iSuccess Move "qa_data/p7s/pass-wallet/manifest.json" To sManifestPath Get ComWriteFile Of hoSbJson sManifestPath "utf-8" False To iSuccess Get ComAppendOneFileOrDir Of hoZip "manifest.json" False To iSuccess // Make sure we have the Apple WWDR intermediate certificate available for // the cert chain in the signature. Get Create (RefClass(cComChilkatXmlCertVault)) To hoCertVault If (Not(IsComObjectCreated(hoCertVault))) Begin Send CreateComObject of hoCertVault End Get Create (RefClass(cComChilkatCert)) To hoAppleWwdrCert If (Not(IsComObjectCreated(hoAppleWwdrCert))) Begin Send CreateComObject of hoAppleWwdrCert End Get ComLoadByCommonName Of hoAppleWwdrCert "Apple Worldwide Developer Relations Certification Authority" To iSuccess If (iSuccess <> True) Begin Showln "The Apple WWDR intermediate certificate is not installed." Showln "It is available at https://developer.apple.com/certificationauthority/AppleWWDRCA.cer" Showln "You may alternatively load the .cer like this..." Get ComLoadFromFile Of hoAppleWwdrCert "qa_data/certs/AppleWWDRCA.cer" To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoAppleWwdrCert To sTemp1 Showln sTemp1 Procedure_Return End End Get pvComObject of hoAppleWwdrCert to vAppleWwdrCert Get ComAddCert Of hoCertVault vAppleWwdrCert To iSuccess Get pvComObject of hoCertVault to vCertVault Get ComUseCertVault Of hoCrypt vCertVault To iSuccess // Use a digital certificate and private key from a PFX file (.pfx or .p12). Move "qa_data/pfx/cert_test123.pfx" To sPfxPath Move "test123" To sPfxPassword Get Create (RefClass(cComChilkatCert)) To hoCert If (Not(IsComObjectCreated(hoCert))) Begin Send CreateComObject of hoCert End Get ComLoadPfxFile Of hoCert sPfxPath sPfxPassword To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoCert To sTemp1 Showln sTemp1 Procedure_Return End // Provide the signing cert (with associated private key). Get pvComObject of hoCert to vCert Get ComSetSigningCert Of hoCrypt vCert To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoCrypt To sTemp1 Showln sTemp1 Procedure_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.) Get Create (RefClass(cComChilkatJsonObject)) To hoJsonSignedAttrs If (Not(IsComObjectCreated(hoJsonSignedAttrs))) Begin Send CreateComObject of hoJsonSignedAttrs End Get ComUpdateInt Of hoJsonSignedAttrs "contentType" 1 To iSuccess Get ComUpdateInt Of hoJsonSignedAttrs "signingTime" 1 To iSuccess Get ComEmit Of hoJsonSignedAttrs To sTemp1 Set ComSigningAttributes Of hoCrypt To sTemp1 // Sign the manifest JSON file to produce a file named "signature". Move "qa_data/p7s/pass-wallet/signature" To sSigPath // Create the "signature" file. Get ComCreateP7S Of hoCrypt sManifestPath sSigPath To iSuccess If (iSuccess = False) Begin Get ComLastErrorText Of hoCrypt To sTemp1 Showln sTemp1 Procedure_Return End Get ComAppendOneFileOrDir Of hoZip "signature" False To iSuccess // --------------------------------------------------------------------------------------------- // 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). Get ComWriteZipAndClose Of hoZip To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoZip To sTemp1 Showln sTemp1 Procedure_Return End Showln "Success." End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.