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
(DataFlex) 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.
Use ChilkatAx-9.5.0-win32.pkg Procedure Test Boolean iSuccess Handle hoCompress Handle hoCrypt String sIvHex String sKeyHex Variant vStreamC Handle hoStreamC Variant vStreamE Handle hoStreamE Variant vTaskC Handle hoTaskC Variant vTaskE Handle hoTaskE Variant vBinData Handle hoBinData String sTemp1 Boolean bTemp1 // This requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. // Initialize the compression object. Get Create (RefClass(cComChilkatCompression)) To hoCompress If (Not(IsComObjectCreated(hoCompress))) Begin Send CreateComObject of hoCompress End Set ComAlgorithm Of hoCompress To "deflate" // Initialize the encryption object. Get Create (RefClass(cComChilkatCrypt2)) To hoCrypt If (Not(IsComObjectCreated(hoCrypt))) Begin Send CreateComObject of hoCrypt End Set ComCryptAlgorithm Of hoCrypt To "chacha20" Set ComKeyLength Of hoCrypt To 256 Set ComEncodingMode Of hoCrypt To "hex" Move "000000000000000000000002" To sIvHex Send ComSetEncodedIV To hoCrypt sIvHex "hex" Set ComInitialCount Of hoCrypt To 42 Move "1c9240a5eb55d38af333888604f6b5f0473917c1402b80099dca5cbc207075c0" To sKeyHex Send ComSetEncodedKey To hoCrypt sKeyHex "hex" // Setup the streams. // streamC is for compression Get Create (RefClass(cComChilkatStream)) To hoStreamC If (Not(IsComObjectCreated(hoStreamC))) Begin Send CreateComObject of hoStreamC End // streamE is for encryption Get Create (RefClass(cComChilkatStream)) To hoStreamE If (Not(IsComObjectCreated(hoStreamE))) Begin Send CreateComObject of hoStreamE End // The source for the compressor is a file. Set ComSourceFile Of hoStreamC To "qa_data/hamlet.xml" // The source for the encryptor is the output of the compressor stream. Get pvComObject of hoStreamC to vStreamC Get ComSetSourceStream Of hoStreamE vStreamC To iSuccess // The sink for the encryptor is the output file. Set ComSinkFile Of hoStreamE To "qa_output/compressed_encrypted.dat" // Start the compression and encryption streams in background threads.. Get pvComObject of hoStreamC to vStreamC Get ComCompressStreamAsync Of hoCompress vStreamC To vTaskC If (IsComObject(vTaskC)) Begin Get Create (RefClass(cComChilkatTask)) To hoTaskC Set pvComObject Of hoTaskC To vTaskC End Get pvComObject of hoStreamE to vStreamE Get ComEncryptStreamAsync Of hoCrypt vStreamE To vTaskE If (IsComObject(vTaskE)) Begin Get Create (RefClass(cComChilkatTask)) To hoTaskE Set pvComObject Of hoTaskE To vTaskE End Get ComRun Of hoTaskC To iSuccess Get ComRun Of hoTaskE To iSuccess // 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 (((ComFinished(hoTaskE)) <> True) Or ((ComFinished(hoTaskC)) <> True)) Send ComSleepMs To hoTaskE 20 Loop // check for success.. Get ComTaskSuccess Of hoTaskE To bTemp1 If (bTemp1 <> True) Begin Showln "async encryption failed:" Get ComResultErrorText Of hoTaskE To sTemp1 Showln sTemp1 Move False To iSuccess End // check for success.. Get ComTaskSuccess Of hoTaskC To bTemp1 If (bTemp1 <> True) Begin Showln "async compression failed:" Get ComResultErrorText Of hoTaskC To sTemp1 Showln sTemp1 Move False To iSuccess End Send Destroy of hoTaskE Send Destroy of hoTaskC // Load the file that was produced and decrypt/decompress to verify. Get Create (RefClass(cComChilkatBinData)) To hoBinData If (Not(IsComObjectCreated(hoBinData))) Begin Send CreateComObject of hoBinData End Get ComLoadFile Of hoBinData "qa_output/compressed_encrypted.dat" To iSuccess Get pvComObject of hoBinData to vBinData Get ComDecryptBd Of hoCrypt vBinData To iSuccess Get pvComObject of hoBinData to vBinData Get ComDecompressBd Of hoCompress vBinData To iSuccess // binData should contain the original data.. Get ComWriteFile Of hoBinData "qa_output/original_hamlet.xml" To iSuccess Showln "Finished." End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.