![]() |
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
(Visual FoxPro) 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.
LOCAL lnSuccess LOCAL loCompress LOCAL loCrypt LOCAL lcIvHex LOCAL lcKeyHex LOCAL loStreamC LOCAL loStreamE LOCAL loTaskC LOCAL loTaskE LOCAL loBinData * This requires the Chilkat API to have been previously unlocked. * See Global Unlock Sample for sample code. * Initialize the compression object. * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Compression') loCompress = CreateObject('Chilkat.Compression') loCompress.Algorithm = "deflate" * Initialize the encryption object. * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Crypt2') loCrypt = CreateObject('Chilkat.Crypt2') 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 * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Stream') loStreamC = CreateObject('Chilkat.Stream') * streamE is for encryption * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Stream') loStreamE = CreateObject('Chilkat.Stream') * 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. lnSuccess = 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) lnSuccess = loTaskC.Run() lnSuccess = 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 <> 1) OR (loTaskC.Finished <> 1)) loTaskE.SleepMs(20) ENDDO * check for success.. IF (loTaskE.TaskSuccess <> 1) THEN ? "async encryption failed:" ? loTaskE.ResultErrorText lnSuccess = 0 ENDIF * check for success.. IF (loTaskC.TaskSuccess <> 1) THEN ? "async compression failed:" ? loTaskC.ResultErrorText lnSuccess = 0 ENDIF RELEASE loTaskE RELEASE loTaskC * Load the file that was produced and decrypt/decompress to verify. * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.BinData') loBinData = CreateObject('Chilkat.BinData') lnSuccess = loBinData.LoadFile("qa_output/compressed_encrypted.dat") lnSuccess = loCrypt.DecryptBd(loBinData) lnSuccess = loCompress.DecompressBd(loBinData) * binData should contain the original data.. lnSuccess = 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.