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) Streaming Compression --> Streaming EncryptionDemonstrate how to feed a compression stream into an encryption stream. This example does the following: Data File --> Compress --> Encrypt --> Application Reads
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_OutData // 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) // Our application will be reading the output of streamE. // 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() // Read the compressed and encrypted bytes. loo_OutData = create oleobject li_rc = loo_OutData.ConnectToNewObject("Chilkat_9_5_0.BinData") do while (loo_StreamE.EndOfStream <> 1) if loo_StreamE.DataAvailable = 1 then li_Success = loo_StreamE.ReadBd(loo_OutData) end if loop // 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 // Get any remaining data that needs to be flushed. if loo_StreamE.DataAvailable = 1 then li_Success = loo_StreamE.ReadBd(loo_OutData) end if // Double-check for success.. if loo_TaskE.TaskSuccess <> 1 then Write-Debug "async encryption failed:" Write-Debug loo_TaskE.ResultErrorText li_Success = 0 end if // Double-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 // Save the compressed/encrypted data to a file. loo_OutData.WriteFile("qa_output/compressedEncrypted.dat") Write-Debug "The async compress/encrypt was successful." // Let's decrypt and decompress to further verify... li_Success = loo_Crypt.DecryptBd(loo_OutData) li_Success = loo_Compress.DecompressBd(loo_OutData) // outData should contain the original data.. li_Success = loo_OutData.WriteFile("qa_output/original_hamlet.xml") destroy loo_Compress destroy loo_Crypt destroy loo_StreamC destroy loo_StreamE destroy loo_OutData |
© 2000-2023 Chilkat Software, Inc. All Rights Reserved.