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

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

 

 

 

(DataFlex) 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.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-9.5.0-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.