November 2019
Intermediate to advanced
346 pages
9h 36m
English
In the following steps, we will see how to obtain the hash of a file:
import sysimport hashlibfilename = "python-3.7.2-amd64.exe"
BUF_SIZE = 65536md5 = hashlib.md5()sha256 = hashlib.sha256()
with open(filename, "rb") as f: while True: data = f.read(BUF_SIZE) if not data: break md5.update(data) sha256.update(data)
print("MD5: {0}".format(md5.hexdigest()))print("SHA256: {0}".format(sha256.hexdigest()))
This results in the ...