I am trying to generate a hash for a given file, in this case the hash function got to a binary file (.tgz file) and then generated an error. Is there a way I can read a binary file and generate a md5 hash of it?
The Error I am receiving is:
buffer = buffer.decode('UTF-8') UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbc in position 10: invalid start byte
The source code is:
import hashlib
def HashFile(filename, readBlockSize = 4096):
hash = hashlib.md5()
with open(filename, 'rb') as fileHandle:
while True:
buffer = fileHandle.read(readBlockSize)
if not buffer:
break
buffer = buffer.decode('UTF-8')
hash.update(hashlib.md5(buffer).hexdigest())
return
I am using Python 3.7 on Linux.