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

Tcl Examples

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

 

 

 

(Tcl) 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 Tcl Extension Downloads

Chilkat Tcl Extension Downloads

load ./chilkat.dll

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

#  Initialize the compression object.
set compress [new_CkCompression]

CkCompression_put_Algorithm $compress "deflate"

#  Initialize the encryption object.
set crypt [new_CkCrypt2]

CkCrypt2_put_CryptAlgorithm $crypt "chacha20"
CkCrypt2_put_KeyLength $crypt 256
CkCrypt2_put_EncodingMode $crypt "hex"
set ivHex "000000000000000000000002"
CkCrypt2_SetEncodedIV $crypt $ivHex "hex"
CkCrypt2_put_InitialCount $crypt 42
set keyHex "1c9240a5eb55d38af333888604f6b5f0473917c1402b80099dca5cbc207075c0"
CkCrypt2_SetEncodedKey $crypt $keyHex "hex"

#  Setup the streams.
#  streamC is for compression
set streamC [new_CkStream]

#  streamE is for encryption
set streamE [new_CkStream]

#  The source for the compressor is a file.
CkStream_put_SourceFile $streamC "qa_data/hamlet.xml"
#  The source for the encryptor is the output of the compressor stream.
set success [CkStream_SetSourceStream $streamE $streamC]

#  The sink for the encryptor is the output file.
CkStream_put_SinkFile $streamE "qa_output/compressed_encrypted.dat"

#  Start the compression and encryption streams in background threads..
# taskC is a CkTask
set taskC [CkCompression_CompressStreamAsync $compress $streamC]
# taskE is a CkTask
set taskE [CkCrypt2_EncryptStreamAsync $crypt $streamE]
set success [CkTask_Run $taskC]
set success [CkTask_Run $taskE]

#  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 {[expr [expr [CkTask_get_Finished $taskE] != 1] OR [expr [CkTask_get_Finished $taskC] != 1]]} {
    [CkTask_SleepMs $taskE 20]
}

#  check for success..
if {[expr [CkTask_get_TaskSuccess $taskE] != 1]} then {
    puts "async encryption failed:"
    puts [CkTask_resultErrorText $taskE]
    set success 0
}

#  check for success..
if {[expr [CkTask_get_TaskSuccess $taskC] != 1]} then {
    puts "async compression failed:"
    puts [CkTask_resultErrorText $taskC]
    set success 0
}

delete_CkTask $taskE

delete_CkTask $taskC

#  Load the file that was produced and decrypt/decompress to verify.
set binData [new_CkBinData]

set success [CkBinData_LoadFile $binData "qa_output/compressed_encrypted.dat"]
set success [CkCrypt2_DecryptBd $crypt $binData]
set success [CkCompression_DecompressBd $compress $binData]

#  binData should contain the original data..
set success [CkBinData_WriteFile $binData "qa_output/original_hamlet.xml"]

puts "Finished."

delete_CkCompression $compress
delete_CkCrypt2 $crypt
delete_CkStream $streamC
delete_CkStream $streamE
delete_CkBinData $binData

 

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