Android Question reading full data of file including 0C 0D

Rabbit

Member
Licensed User
Longtime User
Hi,

I noticed when I read file in bytes even text files < less by two bytes when I read file in php in server:
Carriage Return
Line Feed

The problem the Check sum such as MD5 or SHA will be different from the one in any other platform(e.g.: PHP)

This is the code I am using to read and calc the MD5 ( I found it in the forum)

B4X:
    Dim d As String = File.DirRootExternal 
    Dim In As InputStream 
    In = File.OpenInput(d,"test.txt")
    Dim buffer(File.Size(d, "test.txt") ) As Byte
    Count = In.ReadBytes(buffer, 0, buffer.length)
    Log("Count :: " & Count ) 
    Dim Bconv As ByteConverter
    Dim data(buffer.Length) As Byte 
    Log("data :: " & data ) 
    Dim md As MessageDigest
    data = md.GetMessageDigest(buffer, "MD5") 
    Log("Hash: " & Bconv.HexFromBytes(data))


My question: how to include all bytes in the buffer even the
Carriage Return
Line Feed
to calculate the actual check sum for the whole data file? it is important for me for the integrity.

Thank you
 

DonManfred

Expert
Licensed User
Longtime User
you need to use the same lineendings on both platforms to use a crc.
PHP: Load the file to a string. remove all chr$(13) and chr$(10). Calc the CRC
B4A: Load the file to a string. remove all chr$(13) and chr$(10). Calc the CRC
 
Upvote 0
Top