![]() |
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
(DataFlex) Example: Hash Text in ChunksShows how to generate a final hash, like SHA-256, for a large text by processing it in chunks.
Use ChilkatAx-win32.pkg Procedure Test Handle hoCrypt Variant vBd Handle hoBd String s Boolean iSuccess Boolean iSuccess Integer i String sEncodedHash Get Create (RefClass(cComChilkatCrypt2)) To hoCrypt If (Not(IsComObjectCreated(hoCrypt))) Begin Send CreateComObject of hoCrypt End Set ComHashAlgorithm Of hoCrypt To "sha256" Set ComCharset Of hoCrypt To "utf-8" Get Create (RefClass(cComChilkatBinData)) To hoBd If (Not(IsComObjectCreated(hoBd))) Begin Send CreateComObject of hoBd End Move "The quick brown fox jumped over the lazy dog." + (character(13)) + (character(10)) To s // Accumulate the text in a StringBuilder. We'll demonstrate hashing the text in chunks, // and then also hashing the entire text at once to show the results are the same. Get ComAppendString Of hoBd s "utf-8" To iSuccess Get ComHashBeginString Of hoCrypt s To iSuccess Move 0 To i While (i < 200) Get ComAppendString Of hoBd s "utf-8" To iSuccess Get ComHashMoreString Of hoCrypt s To iSuccess Move (i + 1) To i Loop // Get the hash in base64 format. Set ComEncodingMode Of hoCrypt To "base64" Get ComHashFinalENC Of hoCrypt To sEncodedHash Showln "Hash computed in chunks: " sEncodedHash // Let's alternatively compute the hash of the entire amount of data at once, // to show the hash computation is the same: Get pvComObject of hoBd to vBd Get ComHashBdENC Of hoCrypt vBd To sEncodedHash Showln "Hash computed in 1 step: " sEncodedHash // Output: // Hash computed in chunks: unwkVff61k40roRIJizaknreScHaL6frWe37kydXbZQ= // Hash computed in 1 step: unwkVff61k40roRIJizaknreScHaL6frWe37kydXbZQ= End_Procedure |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.