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

Tcl 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

 

 

 

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

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

# check for success..
if {[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-2024 Chilkat Software, Inc. All Rights Reserved.