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
uncategorized

 

 

 

(DataFlex) Sign Manifest File to Generate a Passbook .pkpass in Memory

Demonstrates how to create a Passbook .pkpass archive by creating a signature of a manifest file and then zipping to a .pkpass archive in memory

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 sDigestStr
    Variant vPngData
    Handle hoPngData
    Variant vEntry
    Handle hoEntry
    String sPassJson
    Variant vCert
Vault    Handle hoCertVault
    Variant vAppleWwdrCert
    Handle hoAppleWwdrCert
    Variant vBdPfx
    Handle hoBdPfx
    String sPfxPassword
    Variant vCert
    Handle hoCert
    Handle hoJsonSignedAttrs
    String sSig
    Variant vBdSig
    Handle hoBdSig
    Variant vBdZip
    Handle hoBdZip
    String sTemp1

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

    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 "notUsedAndNeverCreated.zip" To iSuccess

    Set ComHashAlgorithm Of hoCrypt To "sha1"
    // Return hashes as lowercase hex.
    Set ComEncodingMode Of hoCrypt To "hexlower"

    Get Create (RefClass(cComChilkatBinData)) To hoPngData
    If (Not(IsComObjectCreated(hoPngData))) Begin
        Send CreateComObject of hoPngData
    End
    // Assume we load the pngData with bytes for "icon.png" from somewhere, such as a byte array in memory.
    Get pvComObject of hoPngData to vPngData
    Get ComAppendBd Of hoZip "icon.png" vPngData To vEntry
    If (IsComObject(vEntry)) Begin
        Get Create (RefClass(cComChilkatZipEntry)) To hoEntry
        Set pvComObject Of hoEntry To vEntry
    End
    Send Destroy of hoEntry
    Get pvComObject of hoPngData to vPngData
    Get ComHashBdENC Of hoCrypt vPngData To sDigestStr
    Get ComUpdateString Of hoManifest '"icon.png"' sDigestStr To iSuccess

    Get ComClear Of hoPngData To iSuccess
    // Assume we load the pngData with bytes for "icon@2x.png" from somewhere...
    Get pvComObject of hoPngData to vPngData
    Get ComAppendBd Of hoZip "icon@2x.png" vPngData To vEntry
    If (IsComObject(vEntry)) Begin
        Get Create (RefClass(cComChilkatZipEntry)) To hoEntry
        Set pvComObject Of hoEntry To vEntry
    End
    Send Destroy of hoEntry
    Get pvComObject of hoPngData to vPngData
    Get ComHashBdENC Of hoCrypt vPngData To sDigestStr
    Get ComUpdateString Of hoManifest '"icon@2x.png"' sDigestStr To iSuccess

    Get ComClear Of hoPngData To iSuccess
    // Assume we load the pngData with bytes for "logo.png" from somewhere...
    Get pvComObject of hoPngData to vPngData
    Get ComAppendBd Of hoZip "logo.png" vPngData To vEntry
    If (IsComObject(vEntry)) Begin
        Get Create (RefClass(cComChilkatZipEntry)) To hoEntry
        Set pvComObject Of hoEntry To vEntry
    End
    Send Destroy of hoEntry
    Get pvComObject of hoPngData to vPngData
    Get ComHashBdENC Of hoCrypt vPngData To sDigestStr
    Get ComUpdateString Of hoManifest '"logo.png"' sDigestStr To iSuccess

    Get ComClear Of hoPngData To iSuccess
    // Assume we load the pngData with bytes for "logo@2x.png" from somewhere...
    Get pvComObject of hoPngData to vPngData
    Get ComAppendBd Of hoZip "logo@2x.png" vPngData To vEntry
    If (IsComObject(vEntry)) Begin
        Get Create (RefClass(cComChilkatZipEntry)) To hoEntry
        Set pvComObject Of hoEntry To vEntry
    End
    Send Destroy of hoEntry
    Get pvComObject of hoPngData to vPngData
    Get ComHashBdENC Of hoCrypt vPngData To sDigestStr
    Get ComUpdateString Of hoManifest '"logo@2x.png"' sDigestStr To iSuccess

    Move "{ .... }" To sPassJson    //  Contains the contents of pass.json
    Get ComAppendString Of hoZip "pass.json" sPassJson To vEntry
    If (IsComObject(vEntry)) Begin
        Get Create (RefClass(cComChilkatZipEntry)) To hoEntry
        Set pvComObject Of hoEntry To vEntry
    End
    Send Destroy of hoEntry
    Get ComHashStringENC Of hoCrypt sPassJson To sDigestStr
    Get ComUpdateString Of hoManifest '"pass.json"' sDigestStr To iSuccess

    Get ComEmit Of hoManifest To sTemp1
    Get ComAppendString Of hoZip "manifest.json" sTemp1 To vEntry
    If (IsComObject(vEntry)) Begin
        Get Create (RefClass(cComChilkatZipEntry)) To hoEntry
        Set pvComObject Of hoEntry To vEntry
    End
    Send Destroy of hoEntry

    // 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
    Get Create (RefClass(cComChilkatBinData)) To hoBdPfx
    If (Not(IsComObjectCreated(hoBdPfx))) Begin
        Send CreateComObject of hoBdPfx
    End
    // Assume we loaded a PFX into bdPfx....
    Move "test123" To sPfxPassword

    Get Create (RefClass(cComChilkatCert)) To hoCert
    If (Not(IsComObjectCreated(hoCert))) Begin
        Send CreateComObject of hoCert
    End
    Get pvComObject of hoBdPfx to vBdPfx
    Get ComLoadPfxBd Of hoCert vBdPfx 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 to produce a signature
    Set ComEncodingMode Of hoCrypt To "base64"
    Get ComEmit Of hoManifest To sTemp1
    Get ComSignStringENC Of hoCrypt sTemp1 To sSig
    Get Create (RefClass(cComChilkatBinData)) To hoBdSig
    If (Not(IsComObjectCreated(hoBdSig))) Begin
        Send CreateComObject of hoBdSig
    End
    Get ComAppendEncoded Of hoBdSig sSig "base64" To iSuccess
    Get pvComObject of hoBdSig to vBdSig
    Get ComAppendBd Of hoZip "signature" vBdSig To vEntry
    If (IsComObject(vEntry)) Begin
        Get Create (RefClass(cComChilkatZipEntry)) To hoEntry
        Set pvComObject Of hoEntry To vEntry
    End
    Send Destroy of hoEntry

    // ---------------------------------------------------------------------------------------------
    // 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
    Get Create (RefClass(cComChilkatBinData)) To hoBdZip
    If (Not(IsComObjectCreated(hoBdZip))) Begin
        Send CreateComObject of hoBdZip
    End
    Get pvComObject of hoBdZip to vBdZip
    Get ComWriteBd Of hoZip vBdZip 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.