Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

PowerBuilder Examples

Web API Categories

ASN.1
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
Geolocation
Google APIs
Google Calendar
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
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
REST
REST Misc
RSA
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(PowerBuilder) 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

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_BinData

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

//  The sink for the encryptor is the output file.
loo_StreamE.SinkFile = "qa_output/compressed_encrypted.dat"

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

//  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.
do while ((loo_TaskE.Finished <> 1) OR (loo_TaskC.Finished <> 1))
    loo_TaskE.SleepMs(20)
loop

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

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

//  Load the file that was produced and decrypt/decompress to verify.
loo_BinData = create oleobject
li_rc = loo_BinData.ConnectToNewObject("Chilkat_9_5_0.BinData")

li_Success = loo_BinData.LoadFile("qa_output/compressed_encrypted.dat")
li_Success = loo_Crypt.DecryptBd(loo_BinData)
li_Success = loo_Compress.DecompressBd(loo_BinData)

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

Write-Debug "Finished."


destroy loo_Compress
destroy loo_Crypt
destroy loo_StreamC
destroy loo_StreamE
destroy loo_BinData

 

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