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

 

 

 

(PowerBuilder) Streaming Compression --> Streaming Encryption

Demonstrate how to feed a compression stream into an encryption stream. This example does the following:

Data File --> Compress --> Encrypt --> Application Reads

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

integer li_rc
integer li_Success
oleobject loo_Compress
oleobject loo_Crypt
string ls_IvHex
string ls_KeyHex
oleobject loo_StreamC
oleobject loo_StreamE
oleobject loo_TaskC
oleobject loo_TaskE
oleobject loo_OutData

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

//  Initialize the compression object.
loo_Compress = create oleobject
li_rc = loo_Compress.ConnectToNewObject("Chilkat_9_5_0.Compression")
if li_rc < 0 then
    destroy loo_Compress
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_Compress.Algorithm = "deflate"

//  Initialize the encryption object.
loo_Crypt = create oleobject
li_rc = loo_Crypt.ConnectToNewObject("Chilkat_9_5_0.Crypt2")

loo_Crypt.CryptAlgorithm = "chacha20"
loo_Crypt.KeyLength = 256
loo_Crypt.EncodingMode = "hex"
ls_IvHex = "000000000000000000000002"
loo_Crypt.SetEncodedIV(ls_IvHex,"hex")
loo_Crypt.InitialCount = 42
ls_KeyHex = "1c9240a5eb55d38af333888604f6b5f0473917c1402b80099dca5cbc207075c0"
loo_Crypt.SetEncodedKey(ls_KeyHex,"hex")

//  Setup the streams.
//  streamC is for compression
loo_StreamC = create oleobject
li_rc = loo_StreamC.ConnectToNewObject("Chilkat_9_5_0.Stream")

//  streamE is for encryption
loo_StreamE = create oleobject
li_rc = loo_StreamE.ConnectToNewObject("Chilkat_9_5_0.Stream")

//  The source for the compressor is a file.
loo_StreamC.SourceFile = "qa_data/hamlet.xml"
//  The source for the encryptor is the output of the compressor stream.
li_Success = loo_StreamE.SetSourceStream(loo_StreamC)

//  Our application will be reading the output of streamE.
//  Start the compression and encryption streams in background threads..
loo_TaskC = loo_Compress.CompressStreamAsync(loo_StreamC)
loo_TaskE = loo_Crypt.EncryptStreamAsync(loo_StreamE)
li_Success = loo_TaskC.Run()
li_Success = loo_TaskE.Run()

//  Read the compressed and encrypted bytes.
loo_OutData = create oleobject
li_rc = loo_OutData.ConnectToNewObject("Chilkat_9_5_0.BinData")

do while (loo_StreamE.EndOfStream <> 1)
    if loo_StreamE.DataAvailable = 1 then
        li_Success = loo_StreamE.ReadBd(loo_OutData)
    end if

loop

//  Let's make sure the background task finished.
//  It should already be the case that the task is finished.
do while ((loo_TaskE.Finished <> 1) OR (loo_TaskC.Finished <> 1))
    loo_TaskE.SleepMs(20)
loop

//  Get any remaining data that needs to be flushed.
if loo_StreamE.DataAvailable = 1 then
    li_Success = loo_StreamE.ReadBd(loo_OutData)
end if

//  Double-check for success..
if loo_TaskE.TaskSuccess <> 1 then
    Write-Debug "async encryption failed:"
    Write-Debug loo_TaskE.ResultErrorText
    li_Success = 0
end if

//  Double-check for success..
if loo_TaskC.TaskSuccess <> 1 then
    Write-Debug "async compression failed:"
    Write-Debug loo_TaskC.ResultErrorText
    li_Success = 0
end if

destroy loo_TaskE
destroy loo_TaskC

//  Save the compressed/encrypted data to a file.
loo_OutData.WriteFile("qa_output/compressedEncrypted.dat")

Write-Debug "The async compress/encrypt was successful."

//  Let's decrypt and decompress to further verify...
li_Success = loo_Crypt.DecryptBd(loo_OutData)
li_Success = loo_Compress.DecompressBd(loo_OutData)

//  outData should contain the original data..
li_Success = loo_OutData.WriteFile("qa_output/original_hamlet.xml")


destroy loo_Compress
destroy loo_Crypt
destroy loo_StreamC
destroy loo_StreamE
destroy loo_OutData

 

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