1
2
3
4
5
6
7
8
9
10
11
import hashlib

def hash_file(filepath):
    hashes = {"md5": hashlib.md5(), "sha1": hashlib.sha1(), "sha256": hashlib.sha256()}
    with open(filepath, "rb") as f:
        while chunk := f.read(8192):
            for h in hashes.values():
                h.update(chunk)
    return {k: h.hexdigest() for k, h in hashes.items()}

print(hash_file("sample.exe"))