Android Question MD5 hash does not match Google Drive MD5 hash

cdsincfl

Member
Licensed User
Longtime User
I am using the following to generate an MD5 hash on a file downloaded from Google drive:

B4X:
Sub getLocalChecksum(sPath As String, fileNameArg As String) As String
    Dim iStream As InputStream = File.OpenInput(sPath, fileNameArg)
    Dim buffer(File.Size(sPath,fileNameArg)) As Byte
    Dim count As Int = iStream.ReadBytes(buffer, 0, buffer.length)
    Dim data(buffer.Length) As Byte
    Dim md As MessageDigest
    data = md.GetMessageDigest(buffer, "MD5")
    Dim bc As ByteConverter
    Dim checksum As String = bc.HexFromBytes(data)

    Return checksum
End Sub

The MD5 hash from Google drive does not match the local file MD5 that I download from Google drive.
I have generated the hash on the same file in the Assets folder that was uploaded and get a different hash.
I have copied the file from the Assets folder to File.DirDefaultExternal and get a different hash on all 3 files.

I downloaded the file from Google drive to the desktop and the hash generated in Windows is the same as the hash from Google drive.
What am I missing here?

I want to compare the hash of the Google drive file to my local file to determine if they are in sync.
 

cdsincfl

Member
Licensed User
Longtime User
The code in my post is correct. I was comparing different files by mistake.
The blunder was all mine.
 
Upvote 0
Top