Hi all,

I have a function which is in both a DLL on my website and in an EXE locally, the function gets the hash of a file, requests a hash of a file from the website (using the dll) and if they are different updates the website file. However even when I know the file is an exact copy the hashes are both different!!!

Here's my function: (it requires CAPICOM v2.0)

VB Code:
  1. Private Function HashFile(filename As String) As String
  2.     Const lngChunkSize = 100000
  3.     Dim theHash As CAPICOM.HashedData
  4.     Dim lngFreeFile As Long
  5.     Dim strChunk As String
  6.    
  7.     Set theHash = New CAPICOM.HashedData
  8.    
  9.     theHash.Algorithm = CAPICOM_HASH_ALGORITHM_MD5
  10.    
  11.     lngFreeFile = FreeFile
  12.    
  13.     Open filename For Binary Access Read As lngFreeFile
  14.     Do
  15.         If lngChunkSize > LOF(lngFreeFile) - Loc(lngFreeFile) Then
  16.             strChunk = Space$(LOF(lngFreeFile) - Loc(lngFreeFile))
  17.         Else
  18.             strChunk = Space$(lngChunkSize)
  19.         End If
  20.         Get lngFreeFile, , strChunk
  21.         theHash.Hash strChunk
  22.     Loop Until Loc(lngFreeFile) = LOF(lngFreeFile)
  23.     Close lngFreeFile
  24.    
  25.     HashFile = theHash.Value
  26.    
  27.     Set theHash = Nothing
  28. End Function