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) Stream a file to compression to encryption to an output file.

Runs a chain of streams to read a source file, compress, encrypt, and write an output file.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoCompress
    Handle hoCrypt
    String sIvHex
    String sKeyHex
    Variant vStreamC
    Handle hoStreamC
    Variant vStreamE
    Handle hoStreamE
    Variant vTaskC
    Handle hoTaskC
    Variant vTaskE
    Handle hoTaskE
    Variant vBinData
    Handle hoBinData
    String sTemp1
    Boolean bTemp1

    //  This requires the Chilkat API to have been previously unlocked.
    //  See Global Unlock Sample for sample code.

    //  Initialize the compression object.
    Get Create (RefClass(cComChilkatCompression)) To hoCompress
    If (Not(IsComObjectCreated(hoCompress))) Begin
        Send CreateComObject of hoCompress
    End
    Set ComAlgorithm Of hoCompress To "deflate"

    //  Initialize the encryption object.
    Get Create (RefClass(cComChilkatCrypt2)) To hoCrypt
    If (Not(IsComObjectCreated(hoCrypt))) Begin
        Send CreateComObject of hoCrypt
    End
    Set ComCryptAlgorithm Of hoCrypt To "chacha20"
    Set ComKeyLength Of hoCrypt To 256
    Set ComEncodingMode Of hoCrypt To "hex"
    Move "000000000000000000000002" To sIvHex
    Send ComSetEncodedIV To hoCrypt sIvHex "hex"
    Set ComInitialCount Of hoCrypt To 42
    Move "1c9240a5eb55d38af333888604f6b5f0473917c1402b80099dca5cbc207075c0" To sKeyHex
    Send ComSetEncodedKey To hoCrypt sKeyHex "hex"

    //  Setup the streams.
    //  streamC is for compression
    Get Create (RefClass(cComChilkatStream)) To hoStreamC
    If (Not(IsComObjectCreated(hoStreamC))) Begin
        Send CreateComObject of hoStreamC
    End
    //  streamE is for encryption
    Get Create (RefClass(cComChilkatStream)) To hoStreamE
    If (Not(IsComObjectCreated(hoStreamE))) Begin
        Send CreateComObject of hoStreamE
    End

    //  The source for the compressor is a file.
    Set ComSourceFile Of hoStreamC To "qa_data/hamlet.xml"
    //  The source for the encryptor is the output of the compressor stream.
    Get pvComObject of hoStreamC to vStreamC
    Get ComSetSourceStream Of hoStreamE vStreamC To iSuccess

    //  The sink for the encryptor is the output file.
    Set ComSinkFile Of hoStreamE To "qa_output/compressed_encrypted.dat"

    //  Start the compression and encryption streams in background threads..
    Get pvComObject of hoStreamC to vStreamC
    Get ComCompressStreamAsync Of hoCompress vStreamC To vTaskC
    If (IsComObject(vTaskC)) Begin
        Get Create (RefClass(cComChilkatTask)) To hoTaskC
        Set pvComObject Of hoTaskC To vTaskC
    End
    Get pvComObject of hoStreamE to vStreamE
    Get ComEncryptStreamAsync Of hoCrypt vStreamE To vTaskE
    If (IsComObject(vTaskE)) Begin
        Get Create (RefClass(cComChilkatTask)) To hoTaskE
        Set pvComObject Of hoTaskE To vTaskE
    End
    Get ComRun Of hoTaskC To iSuccess
    Get ComRun Of hoTaskE To iSuccess

    //  Let the streams run until finished.
    //  Let's make sure the background task finished.
    //  It should already be the case that the task is finished.
    While (((ComFinished(hoTaskE)) <> True) Or ((ComFinished(hoTaskC)) <> True))
        Send ComSleepMs To hoTaskE 20
    Loop

    //  check for success..
    Get ComTaskSuccess Of hoTaskE To bTemp1
    If (bTemp1 <> True) Begin
        Showln "async encryption failed:"
        Get ComResultErrorText Of hoTaskE To sTemp1
        Showln sTemp1
        Move False To iSuccess
    End

    //  check for success..
    Get ComTaskSuccess Of hoTaskC To bTemp1
    If (bTemp1 <> True) Begin
        Showln "async compression failed:"
        Get ComResultErrorText Of hoTaskC To sTemp1
        Showln sTemp1
        Move False To iSuccess
    End

    Send Destroy of hoTaskE
    Send Destroy of hoTaskC

    //  Load the file that was produced and decrypt/decompress to verify.
    Get Create (RefClass(cComChilkatBinData)) To hoBinData
    If (Not(IsComObjectCreated(hoBinData))) Begin
        Send CreateComObject of hoBinData
    End
    Get ComLoadFile Of hoBinData "qa_output/compressed_encrypted.dat" To iSuccess
    Get pvComObject of hoBinData to vBinData
    Get ComDecryptBd Of hoCrypt vBinData To iSuccess
    Get pvComObject of hoBinData to vBinData
    Get ComDecompressBd Of hoCompress vBinData To iSuccess

    //  binData should contain the original data..
    Get ComWriteFile Of hoBinData "qa_output/original_hamlet.xml" To iSuccess

    Showln "Finished."


End_Procedure

 

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