|  | 
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
| (Unicode C) Compress and Encrypt a Large File (Low and Constant Memory Footprint)See more Compression ExamplesDemonstrates how to compress and encrypt a large file such that the memory footprint remains low and constant.Note: This example requires Chilkat v9.5.0.99 or greater. 
 #include <C_CkCompressionW.h> #include <C_CkJsonObjectW.h> #include <C_CkCrypt2W.h> void ChilkatSample(void) { HCkCompressionW compress; BOOL success; HCkJsonObjectW json; const wchar_t *inPath; const wchar_t *outPath; const wchar_t *inPath2; const wchar_t *outPath2; HCkCrypt2W crypt; const wchar_t *decryptedPath; const wchar_t *outPath3; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. compress = CkCompressionW_Create(); CkCompressionW_putAlgorithm(compress,L"deflate"); // Set encryption params. // The possible values are the same as for the corresponding properties in the Chilkat Crypt2 class/object. // The encoded IV and Key must be specified as hex. json = CkJsonObjectW_Create(); CkJsonObjectW_UpdateString(json,L"cryptAlgorithm",L"aes"); CkJsonObjectW_UpdateString(json,L"cipherMode",L"cbc"); CkJsonObjectW_UpdateInt(json,L"keyLength",128); CkJsonObjectW_UpdateInt(json,L"paddingScheme",0); CkJsonObjectW_UpdateString(json,L"encodedIV",L"000102030405060708090A0B0C0D0E0F"); CkJsonObjectW_UpdateString(json,L"encodedKey",L"000102030405060708090A0B0C0D0E0F"); // Do file-to-file compression+encryption in a single call. inPath = L"qa_data/largeFile.dat"; outPath = L"c:/temp/qa_output/compressed_encrypted.dat"; success = CkCompressionW_CompressEncryptFile(compress,json,inPath,outPath); if (success == FALSE) { wprintf(L"%s\n",CkCompressionW_lastErrorText(compress)); CkCompressionW_Dispose(compress); CkJsonObjectW_Dispose(json); return; } // We can do file-to-file decrypt/decompress like this: inPath2 = outPath; outPath2 = L"c:/temp/qa_output/restored.dat"; success = CkCompressionW_DecryptDecompressFile(compress,json,inPath2,outPath2); if (success == FALSE) { wprintf(L"%s\n",CkCompressionW_lastErrorText(compress)); CkCompressionW_Dispose(compress); CkJsonObjectW_Dispose(json); return; } // Note: The above decrypt + decompress is the equivalent of doing the same in these two steps: crypt = CkCrypt2W_Create(); CkCrypt2W_putCryptAlgorithm(crypt,L"aes"); CkCrypt2W_putCipherMode(crypt,L"cbc"); CkCrypt2W_putKeyLength(crypt,128); CkCrypt2W_putPaddingScheme(crypt,0); CkCrypt2W_SetEncodedIV(crypt,L"000102030405060708090A0B0C0D0E0F",L"hex"); CkCrypt2W_SetEncodedKey(crypt,L"000102030405060708090A0B0C0D0E0F",L"hex"); decryptedPath = L"c:/temp/qa_output/decrypted.dat"; success = CkCrypt2W_CkDecryptFile(crypt,inPath2,decryptedPath); if (success == FALSE) { wprintf(L"%s\n",CkCrypt2W_lastErrorText(crypt)); CkCompressionW_Dispose(compress); CkJsonObjectW_Dispose(json); CkCrypt2W_Dispose(crypt); return; } outPath3 = L"c:/temp/qa_output/restored_in_two_steps.dat"; success = CkCompressionW_DecompressFile(compress,decryptedPath,outPath3); if (success == FALSE) { wprintf(L"%s\n",CkCompressionW_lastErrorText(compress)); CkCompressionW_Dispose(compress); CkJsonObjectW_Dispose(json); CkCrypt2W_Dispose(crypt); return; } wprintf(L"Success.\n"); CkCompressionW_Dispose(compress); CkJsonObjectW_Dispose(json); CkCrypt2W_Dispose(crypt); } | ||||||
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.