Skip to content

Instantly share code, notes, and snippets.

@jakekara
Created September 1, 2018 21:11
Show Gist options
  • Select an option

  • Save jakekara/078899caaf8d5e6c74ef58d16ce7e703 to your computer and use it in GitHub Desktop.

Select an option

Save jakekara/078899caaf8d5e6c74ef58d16ce7e703 to your computer and use it in GitHub Desktop.
get a sha256 digest of a file using python's hashlib
""" Hash a file supplied by argv[1] """
from sys import argv
from hashlib import sha256
# Construct an sha256 algorith
h256 = sha256()
# Get the name of the file we want to hash
fname = argv[1]
# Read the contents of the file into the hash algorithm
h256.update(open(fname,'rb').read())
# Print the digest/hash of the file's contents
print (h256.hexdigest())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment