from hashlib import md5def encrypt_md5(s): # 创建md5对象 new_md5 = md5() # 这里必须用encode()函数对字符串进行编码,不然会报 TypeError: Unicode-objects must be encoded before hashing new_md5.update(s.encode(encoding='utf-8')) # 加密 return new_md5.hexdigest()# 调用if __name__ == '__main__': print(encrypt_md5('admin'))
输出结果:
21232f297a57a5a743894a0e4a801fc3