md5加密
import hashlib
s="1234wxy"
bs=s.encode()#加密需要把str通过encode转换成byte类型
m=hashlib.md5(bs)#把字符串加密命令
m=hashlib.sha512(bs)
print(m.hexdigest())#运行结果:606fe474b1771c289cbdf4fd74ed100d
md5加盐函数
def my_md5(s,salt=""):
new_s=str(s)+salt
m=hashlib.md5(new_s.encode())
return m.hexdigest()
base64加密
import base64
s = "wanshu、+@#%chengsdgsdgsdgsdgssgsgsg"
result = base64.b64encode(s.encode()).decode()
print(result)
#结果返回:d2Fuc2h1Y2hlbmdzZGdzZGdzZGdzZGdzc2dzZ3Nn
s1 = "d2Fuc2h1Y2hlbmdzZGdzZGdzZGdzZGdzc2dzZ3Nn"
result = base64.b64decode(s1).decode()
print(result)