import  hashlib

m=hashlib.md5()

bytes类型才能加密
passwd='jd123'
print(passwd.encode())#把字符串转成bytes类型

print(m.__doc__)#查看方法

m.update(passwd.encode())#不能直接对字符串加密,要先把字符串转成bytes类型
print(m.hexdigest())


MD5加密是不可逆

撞库
befor after



# 加密方法函数

def my_md5(str):
import hashlib
new_str=str.encode()#把字符串转成bytes类型
# new_str=b'%s'%str #把字符串转成bytes类型
m=hashlib.md5() #实例化md5对象
m.update(new_str) #加密
return m.hexdigest() #获取结果返回

# m=hashlib.sha256()
# m.update(passwd.encode())
# print(m.hexdigest())

# res=my_md5('jd')
# print(res)

























posted on 2018-05-04 11:21  彼得潘jd  阅读(143)  评论(0编辑  收藏  举报