Python cryptographic checksums Source

1---2title: 'Python cryptographic checksums'3date: '2007-05-07'4published_at: '2007-05-07T13:36:00.000+10:00'5tags: ['crypto', 'programming', 'python']6author: 'Gavin Jackson'7excerpt: 'Python provides a pretty handy module for performin MD5 sums of both text and data buffers. The following function provides an MD5 sum given a file name: def get_hash(self, filename): """ Generates an...'8updated_at: '2007-05-08T13:49:36.669+10:00'9legacy_url: 'http://www.gavinj.net/2007/05/python-cryptographic-checksums.html'10---1112Python provides a pretty handy module for performin MD5 sums of both text and data buffers. The following function provides an MD5 sum given a file name:1314```15def get_hash(self, filename):16  """17        Generates an md5 sum of a file18  """19  f = file(filename,'rb');20  m = md5.new();21  readBytes = 1024; # read 1024 bytes per time22  totalBytes = 0;23  while (readBytes):24      readString = f.read(readBytes);25      m.update(readString);26      readBytes = len(readString);27      totalBytes+=readBytes;28  f.close();29  return m.hexdigest();30```313233