Method one: compute the MD5 sum using Python's APIs:
infile = open("filename", 'rb')Method two: using the OS command `md5` on Linux, or the Windows command line utility available for download:
content = infile.read()
infile.close()
m = hashlib.md5() # don't forget to "import hashlib"
m.update(content)
md5 = m.hexdigest() # now the md5 variable contains the MD5 sum
p = subprocess.Popen("md5 " + "filename", shell = True, stdout=subprocess.PIPE) # don't forget to "import subprocess"That all folks.
md5 = p.stdout.readline().split() # now the md5 variable contains the MD5 sum
p.wait() # some clean up
Great post! exactly what i needed
ReplyDeleter. atias
Was using the md5 module before..
ReplyDeleteThank you.
http://vimalkumar.in
In newer versions you can do:
ReplyDeletehashlib.md5("password").hexdigest()
Good post, though; it led me to what I needed.