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
(PowerBuilder) 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
integer li_rc integer li_Success oleobject loo_Manifest oleobject loo_Crypt oleobject loo_Zip string ls_DigestStr oleobject loo_PngData oleobject loo_Entry string ls_PassJson oleobject loo_CertVault oleobject loo_AppleWwdrCert oleobject loo_BdPfx string ls_PfxPassword oleobject loo_Cert oleobject loo_JsonSignedAttrs string ls_Sig oleobject loo_BdSig oleobject loo_BdZip // 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 loo_Manifest = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 li_rc = loo_Manifest.ConnectToNewObject("Chilkat.JsonObject") if li_rc < 0 then destroy loo_Manifest MessageBox("Error","Connecting to COM object failed") return end if loo_Crypt = create oleobject // Use "Chilkat_9_5_0.Crypt2" for versions of Chilkat < 10.0.0 li_rc = loo_Crypt.ConnectToNewObject("Chilkat.Crypt2") loo_Zip = create oleobject // Use "Chilkat_9_5_0.Zip" for versions of Chilkat < 10.0.0 li_rc = loo_Zip.ConnectToNewObject("Chilkat.Zip") loo_Zip.NewZip("notUsedAndNeverCreated.zip") loo_Crypt.HashAlgorithm = "sha1" // Return hashes as lowercase hex. loo_Crypt.EncodingMode = "hexlower" loo_PngData = create oleobject // Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0 li_rc = loo_PngData.ConnectToNewObject("Chilkat.BinData") // Assume we load the pngData with bytes for "icon.png" from somewhere, such as a byte array in memory. loo_Entry = loo_Zip.AppendBd("icon.png",loo_PngData) destroy loo_Entry ls_DigestStr = loo_Crypt.HashBdENC(loo_PngData) loo_Manifest.UpdateString("~"icon.png~"",ls_DigestStr) loo_PngData.Clear() // Assume we load the pngData with bytes for "icon@2x.png" from somewhere... loo_Entry = loo_Zip.AppendBd("icon@2x.png",loo_PngData) destroy loo_Entry ls_DigestStr = loo_Crypt.HashBdENC(loo_PngData) loo_Manifest.UpdateString("~"icon@2x.png~"",ls_DigestStr) loo_PngData.Clear() // Assume we load the pngData with bytes for "logo.png" from somewhere... loo_Entry = loo_Zip.AppendBd("logo.png",loo_PngData) destroy loo_Entry ls_DigestStr = loo_Crypt.HashBdENC(loo_PngData) loo_Manifest.UpdateString("~"logo.png~"",ls_DigestStr) loo_PngData.Clear() // Assume we load the pngData with bytes for "logo@2x.png" from somewhere... loo_Entry = loo_Zip.AppendBd("logo@2x.png",loo_PngData) destroy loo_Entry ls_DigestStr = loo_Crypt.HashBdENC(loo_PngData) loo_Manifest.UpdateString("~"logo@2x.png~"",ls_DigestStr) ls_PassJson = "{ .... }"// Contains the contents of pass.json loo_Entry = loo_Zip.AppendString("pass.json",ls_PassJson) destroy loo_Entry ls_DigestStr = loo_Crypt.HashStringENC(ls_PassJson) loo_Manifest.UpdateString("~"pass.json~"",ls_DigestStr) loo_Entry = loo_Zip.AppendString("manifest.json",loo_Manifest.Emit()) destroy loo_Entry // Make sure we have the Apple WWDR intermediate certificate available for // the cert chain in the signature. loo_CertVault = create oleobject // Use "Chilkat_9_5_0.XmlCertVault" for versions of Chilkat < 10.0.0 li_rc = loo_CertVault.ConnectToNewObject("Chilkat.XmlCertVault") loo_AppleWwdrCert = create oleobject // Use "Chilkat_9_5_0.Cert" for versions of Chilkat < 10.0.0 li_rc = loo_AppleWwdrCert.ConnectToNewObject("Chilkat.Cert") li_Success = loo_AppleWwdrCert.LoadByCommonName("Apple Worldwide Developer Relations Certification Authority") if li_Success <> 1 then Write-Debug "The Apple WWDR intermediate certificate is not installed." Write-Debug "It is available at https://developer.apple.com/certificationauthority/AppleWWDRCA.cer" Write-Debug "You may alternatively load the .cer like this..." li_Success = loo_AppleWwdrCert.LoadFromFile("qa_data/certs/AppleWWDRCA.cer") if li_Success <> 1 then Write-Debug loo_AppleWwdrCert.LastErrorText destroy loo_Manifest destroy loo_Crypt destroy loo_Zip destroy loo_PngData destroy loo_CertVault destroy loo_AppleWwdrCert return end if end if loo_CertVault.AddCert(loo_AppleWwdrCert) loo_Crypt.UseCertVault(loo_CertVault) // Use a digital certificate and private key from a PFX loo_BdPfx = create oleobject // Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0 li_rc = loo_BdPfx.ConnectToNewObject("Chilkat.BinData") // Assume we loaded a PFX into bdPfx.... ls_PfxPassword = "test123" loo_Cert = create oleobject // Use "Chilkat_9_5_0.Cert" for versions of Chilkat < 10.0.0 li_rc = loo_Cert.ConnectToNewObject("Chilkat.Cert") li_Success = loo_Cert.LoadPfxBd(loo_BdPfx,ls_PfxPassword) if li_Success <> 1 then Write-Debug loo_Cert.LastErrorText destroy loo_Manifest destroy loo_Crypt destroy loo_Zip destroy loo_PngData destroy loo_CertVault destroy loo_AppleWwdrCert destroy loo_BdPfx destroy loo_Cert return end if // Provide the signing cert (with associated private key). li_Success = loo_Crypt.SetSigningCert(loo_Cert) if li_Success <> 1 then Write-Debug loo_Crypt.LastErrorText destroy loo_Manifest destroy loo_Crypt destroy loo_Zip destroy loo_PngData destroy loo_CertVault destroy loo_AppleWwdrCert destroy loo_BdPfx destroy loo_Cert return end if // 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.) loo_JsonSignedAttrs = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 li_rc = loo_JsonSignedAttrs.ConnectToNewObject("Chilkat.JsonObject") loo_JsonSignedAttrs.UpdateInt("contentType",1) loo_JsonSignedAttrs.UpdateInt("signingTime",1) loo_Crypt.SigningAttributes = loo_JsonSignedAttrs.Emit() // Sign the manifest JSON to produce a signature loo_Crypt.EncodingMode = "base64" ls_Sig = loo_Crypt.SignStringENC(loo_Manifest.Emit()) loo_BdSig = create oleobject // Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0 li_rc = loo_BdSig.ConnectToNewObject("Chilkat.BinData") loo_BdSig.AppendEncoded(ls_Sig,"base64") loo_Entry = loo_Zip.AppendBd("signature",loo_BdSig) destroy loo_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 loo_BdZip = create oleobject // Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0 li_rc = loo_BdZip.ConnectToNewObject("Chilkat.BinData") li_Success = loo_Zip.WriteBd(loo_BdZip) if li_Success <> 1 then Write-Debug loo_Zip.LastErrorText destroy loo_Manifest destroy loo_Crypt destroy loo_Zip destroy loo_PngData destroy loo_CertVault destroy loo_AppleWwdrCert destroy loo_BdPfx destroy loo_Cert destroy loo_JsonSignedAttrs destroy loo_BdSig destroy loo_BdZip return end if Write-Debug "Success." destroy loo_Manifest destroy loo_Crypt destroy loo_Zip destroy loo_PngData destroy loo_CertVault destroy loo_AppleWwdrCert destroy loo_BdPfx destroy loo_Cert destroy loo_JsonSignedAttrs destroy loo_BdSig destroy loo_BdZip |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.