crypto modules

This commit is contained in:
Mari Wahl 2015-01-03 20:47:39 -05:00
parent f211c1cbab
commit 5fcb5a5cb9
28 changed files with 122 additions and 7 deletions

View file

@ -0,0 +1,21 @@
#!/usr/bin/env python
__author__ = "bt3"
'''
Calculate the MD5 checksum of a file.
We work on chunks to avoid using too much memory when the file is large.
'''
import os
from Crypto.Hash import MD5
def get_file_checksum(filename):
h = MD5.new()
chunk_size = 8192
with open(filename, 'rb') as f:
while True:
chunk = f.read(chunk_size)
if len(chunk) == 0:
break
h.update(chunk)
return h.hexdigest()