class MD5Sign():
@staticmethod
def md5_sign(sign_data):
import hashlib
if not sign_data:
raise Exception('sign_data can not be blank.') #判断是否有数据
md5 = hashlib.md5()
md5.update(sign_data.encode('utf-8')) # 注意转码
md5_digest = md5.hexdigest()
# print("md5加密结果:", md5_digest)
return md5_digest
@staticmethod
def md5_verify(verify_data, sign):
import hashlib
if not verify_data or not sign:
raise Exception('verify_data or sign can not be blank.')
md5 = hashlib.md5()
md5.update(verify_data.encode('utf-8')) # 注意转码
md5_digest = md5.hexdigest()
return md5_digest == sign