3

I am trying to get SHA1 checksum of multiple files.

I tried solution form this thread Generating one MD5/SHA1 checksum of multiple files in Python

So I put together following:

    MainScene = "C:/MainScene.xml"
    MainScreen = "C:/MainScreen.xml"
    Main = "C:/main.brs"
    Manifest = "C:/manifest"
    flist= [MainScene,MainScreen,Main,Manifest]
    hash_obj = hashlib.sha1(open(flist[0], 'rb').read())
    for fname in flist[1:]:
        hash_obj.update(open(fname, 'rb').read())
    checksum = hash_obj.digest()
    print checksum

But output would be:

But it gives me wrong results:

'\xdcRjgd\xcb"1\xadZ\x88\xf2\xb6\x18\xd7i)\x19\xc7)'

Which is not correct, I think that issue is with my files list, can someone please tell me what is wrong about it?

4
  • Why is that the wrong result - what are you expecting? Do you mean to use .hexdigest() for instance? Commented Jul 31, 2017 at 8:27
  • Sorry if dumb question, as i am pretty new to this, but i expect something like this: "a5ed2fab88bd0f714f417b55b690c2bc8c1d8d9e" Commented Jul 31, 2017 at 8:31
  • 4
    use .hexdigest() instead of .digest() ? Commented Jul 31, 2017 at 8:35
  • Thank you, this simple change did the trick! Commented Jul 31, 2017 at 10:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.