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) Dropbox Content HashDemonstrates how to compute the Dropbox content_hash of a file. (This is the "content_hash" found in the Dropbox FileMetadata object. Note: This example requires Chilkat v9.5.0.79 or greater because it uses the fac.ReadBlockBd method. For more information, see https://www.dropbox.com/developers/reference/content-hash
integer li_rc oleobject loo_Crypt oleobject loo_Fac oleobject loo_Bd oleobject loo_BdHashes integer li_Success integer li_BlockSize integer li_NumBlocks integer i string ls_HashHex string ls_Content_hash // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. loo_Crypt = create oleobject // Use "Chilkat_9_5_0.Crypt2" for versions of Chilkat < 10.0.0 li_rc = loo_Crypt.ConnectToNewObject("Chilkat.Crypt2") if li_rc < 0 then destroy loo_Crypt MessageBox("Error","Connecting to COM object failed") return end if // To calculate the content_hash of a file: // Split the file into blocks of 4 MB (4,194,304 or 4 * 1024 * 1024 bytes). The last block (if any) may be smaller than 4 MB. // Compute the hash of each block using SHA-256. // Concatenate the hash of all blocks in the binary format to form a single binary string. // Compute the hash of the concatenated string using SHA-256. Output the resulting hash in hexadecimal format. loo_Crypt.HashAlgorithm = "sha256" loo_Crypt.EncodingMode = "hex_lower" // We're going to calculate the content_hash for the Milky Way JPG image linked here: https://www.dropbox.com/developers/reference/content-hash loo_Fac = create oleobject // Use "Chilkat_9_5_0.FileAccess" for versions of Chilkat < 10.0.0 li_rc = loo_Fac.ConnectToNewObject("Chilkat.FileAccess") loo_Bd = create oleobject // Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0 li_rc = loo_Bd.ConnectToNewObject("Chilkat.BinData") loo_BdHashes = create oleobject // Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0 li_rc = loo_BdHashes.ConnectToNewObject("Chilkat.BinData") li_Success = loo_Fac.OpenForRead("qa_data/jpg/milky-way-nasa.jpg") if li_Success = 0 then Write-Debug loo_Fac.LastErrorText destroy loo_Crypt destroy loo_Fac destroy loo_Bd destroy loo_BdHashes return end if li_BlockSize = 4194304 li_NumBlocks = loo_Fac.GetNumBlocks(li_BlockSize) i = 0 do while (i < li_NumBlocks) // Read the next 4MB block into bd. loo_Bd.Clear() li_Success = loo_Fac.ReadBlockBd(i,li_BlockSize,loo_Bd) ls_HashHex = loo_Crypt.HashBdENC(loo_Bd) Write-Debug string(i) + ": " + ls_HashHex loo_BdHashes.AppendEncoded(ls_HashHex,"hex_lower") i = i + 1 loop loo_Fac.FileClose() // Hash the concatenated SHA-256 hashes. ls_Content_hash = loo_Crypt.HashBdENC(loo_BdHashes) Write-Debug "content_hash = " + ls_Content_hash destroy loo_Crypt destroy loo_Fac destroy loo_Bd destroy loo_BdHashes |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.