Exemple #1
0
def md5(key):
    """
    Create md5 hash
    """
    m = hashlib_md5()
    m.update(str(key))
    return m.hexdigest()
Exemple #2
0
def md5_hash(file_path):
    """this hash function receives the name of the file and returns the hash code"""
    readsize = 64 * 1024
    with open(file_path, 'rb') as f:
        data = f.read(readsize)
        f.seek(-readsize, 2)
        data += f.read(readsize)
    return hashlib_md5(data).hexdigest()
Exemple #3
0
  def makeguid(self, data):
    "Generate a windows style GUID"
    ### blah. this function can generate invalid GUIDs. leave it for now,
    ### but we need to fix it. we can wrap the apr UUID functions, or
    ### implement this from scratch using the algorithms described in
    ### http://www.webdav.org/specs/draft-leach-uuids-guids-01.txt

    myhash = hashlib_md5(data).hexdigest()

    guid = ("{%s-%s-%s-%s-%s}" % (myhash[0:8], myhash[8:12],
                                  myhash[12:16], myhash[16:20],
                                  myhash[20:32])).upper()
    return guid
def shooter_hash(file_path):
    "see https://docs.google.com/document/d/1w5MCBO61rKQ6hI5m9laJLWse__yTYdRugpVyz4RzrmM/preview"
    f_size = getsize(file_path)
    if f_size < 8196:
        print '文件太小了……你确定选中的是视频文件么……'.encode(getfilesystemencoding())
        return None
    with open(file_path, 'rb') as f:
        f_size_3rd = int(f_size / 3)
        # 中间两个顺序反了?作者文档上就是这么写的。。。
        offsets = (4096, f_size_3rd * 2, f_size_3rd, f_size - 8192)
        result = []
        for offset in offsets:
            f.seek(offset)
            result.append(hashlib_md5(f.read(4096)).hexdigest())
        return ';'.join(result)
Exemple #5
0
 def gen_seed(self):
   # Return a base64-encoded (kinda ... strip the '==\n' from the
   # end) MD5 hash of sorted tree listing.
   self.allfiles.sort()
   return base64.encodestring(hashlib_md5(''.join(self.allfiles)).digest())[:-3]
Exemple #6
0
def md5(text):
    if type(text)==unicode:
        text = text.encode('utf-8')
    text = str(text)
    m = hashlib_md5(text)
    return m.hexdigest()
Exemple #7
0
def get_file_hash(filename):
    key = str(os.path.getmtime(filename)) + filename
    return base64.urlsafe_b64encode(hashlib_md5(key).digest()).strip('=')
Exemple #8
0
 def __compute_data_hash(cls, data):
     jdata = json.dumps(data, sort_keys=True, separators=(',', ':'))
     return hashlib_md5(jdata.encode('utf8')).hexdigest()
Exemple #9
0
 def gen_seed(self):
     # Return a base64-encoded (kinda ... strip the '==\n' from the
     # end) MD5 hash of sorted tree listing.
     self.allfiles.sort()
     return base64.encodestring(
         hashlib_md5(''.join(self.allfiles)).digest())[:-3]