Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(AutoIt) Streaming Compression --> Streaming EncryptionDemonstrate how to feed a compression stream into an encryption stream. This example does the following: Data File --> Compress --> Encrypt --> Application Reads
; This requires the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. Local $bSuccess ; Initialize the compression object. $oCompress = ObjCreate("Chilkat_9_5_0.Compression") $oCompress.Algorithm = "deflate" ; Initialize the encryption object. $oCrypt = ObjCreate("Chilkat_9_5_0.Crypt2") $oCrypt.CryptAlgorithm = "chacha20" $oCrypt.KeyLength = 256 $oCrypt.EncodingMode = "hex" Local $sIvHex = "000000000000000000000002" $oCrypt.SetEncodedIV $sIvHex,"hex" $oCrypt.InitialCount = 42 Local $sKeyHex = "1c9240a5eb55d38af333888604f6b5f0473917c1402b80099dca5cbc207075c0" $oCrypt.SetEncodedKey $sKeyHex,"hex" ; Setup the streams. ; streamC is for compression $oStreamC = ObjCreate("Chilkat_9_5_0.Stream") ; streamE is for encryption $oStreamE = ObjCreate("Chilkat_9_5_0.Stream") ; The source for the compressor is a file. $oStreamC.SourceFile = "qa_data/hamlet.xml" ; The source for the encryptor is the output of the compressor stream. $bSuccess = $oStreamE.SetSourceStream($oStreamC) ; Our application will be reading the output of streamE. ; Start the compression and encryption streams in background threads.. Local $oTaskC = $oCompress.CompressStreamAsync($oStreamC) Local $oTaskE = $oCrypt.EncryptStreamAsync($oStreamE) $bSuccess = $oTaskC.Run() $bSuccess = $oTaskE.Run() ; Read the compressed and encrypted bytes. $oOutData = ObjCreate("Chilkat_9_5_0.BinData") While ($oStreamE.EndOfStream <> True) If ($oStreamE.DataAvailable = True) Then $bSuccess = $oStreamE.ReadBd($oOutData) EndIf Wend ; Let's make sure the background task finished. ; It should already be the case that the task is finished. While (($oTaskE.Finished <> True) Or ($oTaskC.Finished <> True)) $oTaskE.SleepMs 20 Wend ; Get any remaining data that needs to be flushed. If ($oStreamE.DataAvailable = True) Then $bSuccess = $oStreamE.ReadBd($oOutData) EndIf ; Double-check for success.. If ($oTaskE.TaskSuccess <> True) Then ConsoleWrite("async encryption failed:" & @CRLF) ConsoleWrite($oTaskE.ResultErrorText & @CRLF) $bSuccess = False EndIf ; Double-check for success.. If ($oTaskC.TaskSuccess <> True) Then ConsoleWrite("async compression failed:" & @CRLF) ConsoleWrite($oTaskC.ResultErrorText & @CRLF) $bSuccess = False EndIf ; Save the compressed/encrypted data to a file. $oOutData.WriteFile("qa_output/compressedEncrypted.dat") ConsoleWrite("The async compress/encrypt was successful." & @CRLF) ; Let's decrypt and decompress to further verify... $bSuccess = $oCrypt.DecryptBd($oOutData) $bSuccess = $oCompress.DecompressBd($oOutData) ; outData should contain the original data.. $bSuccess = $oOutData.WriteFile("qa_output/original_hamlet.xml") |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.