[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:
Private Function HashFile(filename As String) As String
Const lngChunkSize = 100000
Dim theHash As CAPICOM.HashedData
Dim lngFreeFile As Long
Dim strChunk As String
Set theHash = New CAPICOM.HashedData
theHash.Algorithm = CAPICOM_HASH_ALGORITHM_MD5
lngFreeFile = FreeFile
Open filename For Binary Access Read As lngFreeFile
Do
If lngChunkSize > LOF(lngFreeFile) - Loc(lngFreeFile) Then
strChunk = Space$(LOF(lngFreeFile) - Loc(lngFreeFile))
Else
strChunk = Space$(lngChunkSize)
End If
Get lngFreeFile, , strChunk
theHash.Hash strChunk
Loop Until Loc(lngFreeFile) = LOF(lngFreeFile)
Close lngFreeFile
HashFile = theHash.Value
Set theHash = Nothing
End Function
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?
Re: CAPICOM Hash returning different values
Doesnt matter, turns out I was calculating the filename incorrectly before calling the function.