![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Lianja) 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. // Initialize the compression object. loCompress = createobject("CkCompression") loCompress.Algorithm = "deflate" // Initialize the encryption object. loCrypt = createobject("CkCrypt2") loCrypt.CryptAlgorithm = "chacha20" loCrypt.KeyLength = 256 loCrypt.EncodingMode = "hex" lcIvHex = "000000000000000000000002" loCrypt.SetEncodedIV(lcIvHex,"hex") loCrypt.InitialCount = 42 lcKeyHex = "1c9240a5eb55d38af333888604f6b5f0473917c1402b80099dca5cbc207075c0" loCrypt.SetEncodedKey(lcKeyHex,"hex") // Setup the streams. // streamC is for compression loStreamC = createobject("CkStream") // streamE is for encryption loStreamE = createobject("CkStream") // The source for the compressor is a file. loStreamC.SourceFile = "qa_data/hamlet.xml" // The source for the encryptor is the output of the compressor stream. llSuccess = loStreamE.SetSourceStream(loStreamC) // The sink for the encryptor is the output file. loStreamE.SinkFile = "qa_output/compressed_encrypted.dat" // Start the compression and encryption streams in background threads.. loTaskC = loCompress.CompressStreamAsync(loStreamC) loTaskE = loCrypt.EncryptStreamAsync(loStreamE) llSuccess = loTaskC.Run() llSuccess = loTaskE.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. do while ((loTaskE.Finished <> .T.) or (loTaskC.Finished <> .T.)) loTaskE.SleepMs(20) enddo // check for success.. if (loTaskE.TaskSuccess <> .T.) then ? "async encryption failed:" ? loTaskE.ResultErrorText llSuccess = .F. endif // check for success.. if (loTaskC.TaskSuccess <> .T.) then ? "async compression failed:" ? loTaskC.ResultErrorText llSuccess = .F. endif release loTaskE release loTaskC // Load the file that was produced and decrypt/decompress to verify. loBinData = createobject("CkBinData") llSuccess = loBinData.LoadFile("qa_output/compressed_encrypted.dat") llSuccess = loCrypt.DecryptBd(loBinData) llSuccess = loCompress.DecompressBd(loBinData) // binData should contain the original data.. llSuccess = loBinData.WriteFile("qa_output/original_hamlet.xml") ? "Finished." release loCompress release loCrypt release loStreamC release loStreamE release loBinData |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.