File integrity check

hi all,

I need to check the integrity of some downloaded file.
I didn’t find anything about this, tried crypto library but it works only on strings and passing file as a string pipe seems not to work.
I also tried to use the seek io function to get at least the size but it seems not to work on android because of file extension (video and audio). And in any case size could not be enough.

So I was wonderong if i’m missing something or if someone came to this and solved.

To be clear this files are downloaded after in-app buy.

thanks in advance for reading and eventually answerinng. [import]uid: 107375 topic_id: 23252 reply_id: 323252[/import]

Got the answer on irc channel, here the solution for anyone who need it:

crypto = require ("crypto") local path = system.pathForFile( "pathtofile", system.ResourcesDirectory ) local file = io.open(path) local fileContents = file:read("\*a") local md5Digest = crypto.digest(crypto.md5, fileContents) print (md5Digest) [import]uid: 107375 topic_id: 23252 reply_id: 93080[/import]

I seem to be getting different hash values despite using the same code. The hash value calculated on the simulator is different than the one calculated on a Samsung device. My code:

[lua]local crypto = require(“crypto”)

local path = system.pathForFile(filename, system.TemporaryDirectory)
local fh = io.open(path, “r”)
local file_contents = fh:read("*a")

local hash = crypto.digest(crypto.sha1, file_contents)

print(hash)[/lua]

“hash” is not consistent given the same file. Anyone seeing this same problem? [import]uid: 71024 topic_id: 23252 reply_id: 94979[/import]

I just got done testing this with different devices and simulators. I tried a Nexus One, a Samsung Epic, and the iOS simulator: all three generate the same hash. Only the Windows simulator hash is different!

I guess I’ll just use a Mac to generate hashes… [import]uid: 71024 topic_id: 23252 reply_id: 94989[/import]