Results 1 to 3 of 3

Thread: [RESOLVED] CAPICOM Hash returning different values

  1. #1

    Thread Starter
    Hyperactive Member Arachnid13's Avatar
    Join Date
    Jan 2003
    Location
    England
    Posts
    327

    Resolved [RESOLVED] CAPICOM Hash returning different values

    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
    Do you wake up in the morning feeling sleepy and grumpy? Then you must be Snow White

  2. #2

    Thread Starter
    Hyperactive Member Arachnid13's Avatar
    Join Date
    Jan 2003
    Location
    England
    Posts
    327

    Re: CAPICOM Hash returning different values

    http://www.mcse.ms/message1672489.html

    I've just found this article which seems to describe the problem perfectly and puts it down to string encoding, is there something I could do using StrConv?
    Do you wake up in the morning feeling sleepy and grumpy? Then you must be Snow White

  3. #3

    Thread Starter
    Hyperactive Member Arachnid13's Avatar
    Join Date
    Jan 2003
    Location
    England
    Posts
    327

    Re: CAPICOM Hash returning different values

    Doesnt matter, turns out I was calculating the filename incorrectly before calling the function.
    Do you wake up in the morning feeling sleepy and grumpy? Then you must be Snow White

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width