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
(PowerBuilder) 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.
integer li_rc integer li_Success oleobject loo_Compress oleobject loo_Crypt string ls_IvHex string ls_KeyHex oleobject loo_StreamC oleobject loo_StreamE oleobject loo_TaskC oleobject loo_TaskE oleobject loo_BinData // This requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. // Initialize the compression object. loo_Compress = create oleobject li_rc = loo_Compress.ConnectToNewObject("Chilkat_9_5_0.Compression") if li_rc < 0 then destroy loo_Compress MessageBox("Error","Connecting to COM object failed") return end if loo_Compress.Algorithm = "deflate" // Initialize the encryption object. loo_Crypt = create oleobject li_rc = loo_Crypt.ConnectToNewObject("Chilkat_9_5_0.Crypt2") loo_Crypt.CryptAlgorithm = "chacha20" loo_Crypt.KeyLength = 256 loo_Crypt.EncodingMode = "hex" ls_IvHex = "000000000000000000000002" loo_Crypt.SetEncodedIV(ls_IvHex,"hex") loo_Crypt.InitialCount = 42 ls_KeyHex = "1c9240a5eb55d38af333888604f6b5f0473917c1402b80099dca5cbc207075c0" loo_Crypt.SetEncodedKey(ls_KeyHex,"hex") // Setup the streams. // streamC is for compression loo_StreamC = create oleobject li_rc = loo_StreamC.ConnectToNewObject("Chilkat_9_5_0.Stream") // streamE is for encryption loo_StreamE = create oleobject li_rc = loo_StreamE.ConnectToNewObject("Chilkat_9_5_0.Stream") // The source for the compressor is a file. loo_StreamC.SourceFile = "qa_data/hamlet.xml" // The source for the encryptor is the output of the compressor stream. li_Success = loo_StreamE.SetSourceStream(loo_StreamC) // The sink for the encryptor is the output file. loo_StreamE.SinkFile = "qa_output/compressed_encrypted.dat" // Start the compression and encryption streams in background threads.. loo_TaskC = loo_Compress.CompressStreamAsync(loo_StreamC) loo_TaskE = loo_Crypt.EncryptStreamAsync(loo_StreamE) li_Success = loo_TaskC.Run() li_Success = loo_TaskE.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 ((loo_TaskE.Finished <> 1) OR (loo_TaskC.Finished <> 1)) loo_TaskE.SleepMs(20) loop // check for success.. if loo_TaskE.TaskSuccess <> 1 then Write-Debug "async encryption failed:" Write-Debug loo_TaskE.ResultErrorText li_Success = 0 end if // check for success.. if loo_TaskC.TaskSuccess <> 1 then Write-Debug "async compression failed:" Write-Debug loo_TaskC.ResultErrorText li_Success = 0 end if destroy loo_TaskE destroy loo_TaskC // Load the file that was produced and decrypt/decompress to verify. loo_BinData = create oleobject li_rc = loo_BinData.ConnectToNewObject("Chilkat_9_5_0.BinData") li_Success = loo_BinData.LoadFile("qa_output/compressed_encrypted.dat") li_Success = loo_Crypt.DecryptBd(loo_BinData) li_Success = loo_Compress.DecompressBd(loo_BinData) // binData should contain the original data.. li_Success = loo_BinData.WriteFile("qa_output/original_hamlet.xml") Write-Debug "Finished." destroy loo_Compress destroy loo_Crypt destroy loo_StreamC destroy loo_StreamE destroy loo_BinData |
© 2000-2023 Chilkat Software, Inc. All Rights Reserved.