import hashlib
class Md5_enc():
def __init__(self,key="cxj"):
self.key = key
self.maker = hashlib.md5()
def md5_str(self,message):
self.maker.update(bytes(self.key, encoding="utf-8"))
self.maker.update(bytes(message,encoding="utf-8"))
rel = self.maker.hexdigest()
self.maker = hashlib.md5()
return rel
def md5_file(self,filehandle):
while True:
tmp_data = filehandle.read(10240)
if not tmp_data:
break
self.maker.update(tmp_data)
rel = self.maker.hexdigest()
self.maker = hashlib.md5()
return rel