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) 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.
; 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) ; The sink for the encryptor is the output file. $oStreamE.SinkFile = "qa_output/compressed_encrypted.dat" ; 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() ; 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 (($oTaskE.Finished <> True) Or ($oTaskC.Finished <> True)) $oTaskE.SleepMs 20 Wend ; check for success.. If ($oTaskE.TaskSuccess <> True) Then ConsoleWrite("async encryption failed:" & @CRLF) ConsoleWrite($oTaskE.ResultErrorText & @CRLF) $bSuccess = False EndIf ; check for success.. If ($oTaskC.TaskSuccess <> True) Then ConsoleWrite("async compression failed:" & @CRLF) ConsoleWrite($oTaskC.ResultErrorText & @CRLF) $bSuccess = False EndIf ; Load the file that was produced and decrypt/decompress to verify. $oBinData = ObjCreate("Chilkat_9_5_0.BinData") $bSuccess = $oBinData.LoadFile("qa_output/compressed_encrypted.dat") $bSuccess = $oCrypt.DecryptBd($oBinData) $bSuccess = $oCompress.DecompressBd($oBinData) ; binData should contain the original data.. $bSuccess = $oBinData.WriteFile("qa_output/original_hamlet.xml") ConsoleWrite("Finished." & @CRLF) |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.