import hashlib # md5加密 obj = hashlib.md5() obj.update('123456'.encode('utf-8')) ret = obj.hexdigest() print(ret) # e10adc3949ba59abbe56e057f20f883e # 加盐版本 obj = hashlib.md5('admin'.encode('utf-8')) obj.update('123456'.encode('utf-8')) ret = obj.hexdigest() print(ret) # a66abb5684c45962d887564f08346e8d # 两次update的结果,等同于,两个字符串拼接后的加密 obj = hashlib.md5() obj.update('123456'.encode('utf-8')) obj.update('123456'.encode('utf-8')) ret = obj.hexdigest() print(ret) # ea48576f30be1669971699c09ad05c94 obj = hashlib.md5() obj.update('123456123456'.encode('utf-8')) ret = obj.hexdigest() print(ret) # ea48576f30be1669971699c09ad05c94 # 其他加密方式只需要修改调用方法MD5就好,其他都一样