Skip to content

Instantly share code, notes, and snippets.

@jamescherti
Last active December 25, 2022 22:08
Show Gist options
  • Save jamescherti/47e0cd74505147911b483cee11e256b1 to your computer and use it in GitHub Desktop.
Save jamescherti/47e0cd74505147911b483cee11e256b1 to your computer and use it in GitHub Desktop.
A Python method that returns the SHA512 hash of a file.
#!/usr/bin/env python
# License: MIT
# URL: https://gist.github.com/jamescherti/47e0cd74505147911b483cee11e256b1
import hashlib
def sha512sum(filename):
"""Return the SHA512 hash of a file."""
sha512 = hashlib.sha512()
with open(filename, 'rb') as fhandler:
for chunk in iter(lambda: fhandler.read(4096), b''):
sha512.update(chunk)
return sha512.hexdigest()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment