Skip to content

Instantly share code, notes, and snippets.

@atenni
Created February 13, 2020 07:43
Show Gist options
  • Save atenni/81c064167aedfc8c4273fe57f79762f6 to your computer and use it in GitHub Desktop.
Save atenni/81c064167aedfc8c4273fe57f79762f6 to your computer and use it in GitHub Desktop.

Recipe: calculate SHA256 hash of file in Python

import hashlib

FILENAME = ''
hasher = hashlib.sha256()

with open(FILENAME, "rb") as f:
    for byte_block in iter(lambda: f.read(4096),b""):
        hasher.update(byte_block)
    print(hasher.hexdigest())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment