Created
September 1, 2018 21:11
-
-
Save jakekara/078899caaf8d5e6c74ef58d16ce7e703 to your computer and use it in GitHub Desktop.
get a sha256 digest of a file using python's hashlib
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ 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