Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

PowerBuilder Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(PowerBuilder) Sign Manifest File to Generate a Passbook .pkpass file

Demonstrates 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.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

integer li_rc
integer li_Success
oleobject loo_Manifest
oleobject loo_Crypt
oleobject loo_Zip
string ls_FileHash
string ls_FilePath
oleobject loo_SbJson
string ls_ManifestPath
oleobject loo_CertVault
oleobject loo_AppleWwdrCert
string ls_PfxPath
string ls_PfxPassword
oleobject loo_Cert
oleobject loo_JsonSignedAttrs
string ls_SigPath

// 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

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("qa_data/p7s/pass-wallet/example.pkpass")
// Set the AppendFromDir property to prevent that relative paths from being stored in the .pkpass archive.
loo_Zip.AppendFromDir = "qa_data/p7s/pass-wallet/"

loo_Crypt.HashAlgorithm = "sha1"
// Return hashes as lowercase hex.
loo_Crypt.EncodingMode = "hexlower"

ls_FilePath = "qa_data/p7s/pass-wallet/icon.png"
ls_FileHash = loo_Crypt.HashFileENC(ls_FilePath)
loo_Zip.AppendOneFileOrDir("icon.png",0)
loo_Manifest.UpdateString("~"icon.png~"",ls_FileHash)

ls_FilePath = "qa_data/p7s/pass-wallet/icon@2x.png"
ls_FileHash = loo_Crypt.HashFileENC(ls_FilePath)
loo_Zip.AppendOneFileOrDir("icon@2x.png",0)
loo_Manifest.UpdateString("~"icon@2x.png~"",ls_FileHash)

ls_FilePath = "qa_data/p7s/pass-wallet/logo.png"
ls_FileHash = loo_Crypt.HashFileENC(ls_FilePath)
loo_Zip.AppendOneFileOrDir("logo.png",0)
loo_Manifest.UpdateString("~"logo.png~"",ls_FileHash)

ls_FilePath = "qa_data/p7s/pass-wallet/logo@2x.png"
ls_FileHash = loo_Crypt.HashFileENC(ls_FilePath)
loo_Zip.AppendOneFileOrDir("logo@2x.png",0)
loo_Manifest.UpdateString("~"logo@2x.png~"",ls_FileHash)

ls_FilePath = "qa_data/p7s/pass-wallet/pass.json"
ls_FileHash = loo_Crypt.HashFileENC(ls_FilePath)
loo_Zip.AppendOneFileOrDir("pass.json",0)
loo_Manifest.UpdateString("~"pass.json~"",ls_FileHash)

loo_SbJson = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbJson.ConnectToNewObject("Chilkat.StringBuilder")

loo_Manifest.EmitSb(loo_SbJson)
ls_ManifestPath = "qa_data/p7s/pass-wallet/manifest.json"
loo_SbJson.WriteFile(ls_ManifestPath,"utf-8",0)
loo_Zip.AppendOneFileOrDir("manifest.json",0)

// 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_SbJson
        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 file (.pfx or .p12).
ls_PfxPath = "qa_data/pfx/cert_test123.pfx"
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.LoadPfxFile(ls_PfxPath,ls_PfxPassword)
if li_Success <> 1 then
    Write-Debug loo_Cert.LastErrorText
    destroy loo_Manifest
    destroy loo_Crypt
    destroy loo_Zip
    destroy loo_SbJson
    destroy loo_CertVault
    destroy loo_AppleWwdrCert
    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_SbJson
    destroy loo_CertVault
    destroy loo_AppleWwdrCert
    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 file to produce a file named "signature".
ls_SigPath = "qa_data/p7s/pass-wallet/signature"

// Create the "signature" file.
li_Success = loo_Crypt.CreateP7S(ls_ManifestPath,ls_SigPath)
if li_Success = 0 then
    Write-Debug loo_Crypt.LastErrorText
    destroy loo_Manifest
    destroy loo_Crypt
    destroy loo_Zip
    destroy loo_SbJson
    destroy loo_CertVault
    destroy loo_AppleWwdrCert
    destroy loo_Cert
    destroy loo_JsonSignedAttrs
    return
end if

loo_Zip.AppendOneFileOrDir("signature",0)

// ---------------------------------------------------------------------------------------------
// 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).
li_Success = loo_Zip.WriteZipAndClose()
if li_Success <> 1 then
    Write-Debug loo_Zip.LastErrorText
    destroy loo_Manifest
    destroy loo_Crypt
    destroy loo_Zip
    destroy loo_SbJson
    destroy loo_CertVault
    destroy loo_AppleWwdrCert
    destroy loo_Cert
    destroy loo_JsonSignedAttrs
    return
end if

Write-Debug "Success."


destroy loo_Manifest
destroy loo_Crypt
destroy loo_Zip
destroy loo_SbJson
destroy loo_CertVault
destroy loo_AppleWwdrCert
destroy loo_Cert
destroy loo_JsonSignedAttrs

 

© 2000-2024 Chilkat Software, Inc. All Rights Reserved.