2.2 Determining Cryptographic Hash in Python

In Python, it is possible to generate file hashes using the hashlib module, as shown here:

$ pythonPython 2.7.12 (default, Nov 19 2016, 06:48:10)>>> import hashlib>>> content = open(r"log.exe","rb").read()>>> print hashlib.md5(content).hexdigest()6e4e030fbd2ee786e1b6b758d5897316>>> print hashlib.sha256(content).hexdigest()01636faaae739655bf88b39d21834b7dac923386d2b52efb4142cb278061f97f>>> print hashlib.sha1(content).hexdigest()625644bacf83a889038e4a283d29204edc0e9b65

Get Learning Malware Analysis now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.