一、用处
对需要的内容进行加密
一、下载
pip install itsdangerous
二、使用
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
from django.conf import settings
s = Serializer(settings.SECRET_KEY, 60*60)
# 第一个参数是私钥,密文产生的源头,第二个是过期时间,默认3600秒
SECRET_KEY = 'aaaaaaaabbbbbbbbbbbbccccccccccccc'
s = Serializer(SECRET_KEY, 60*60)
# data = 'aaaaa'
# token = s.dumps(data)
# print(token) # b'eyJhbGciOiJIUzUxMiIsImlhdCI6MTYzMDI1MzIwNiwiZXhwIjoxNjMwMjU2ODA2fQ.ImFhYWFhIg.kvLWy4WBcTj7l0uL2rx3x4N1NSGmJSqgOMZkFuPcpIMVU4XVSZhh7OpgNtuQ9Ooc_KWlSLOLN14DlhaNwRNnbw'
# 默认是bytes数据
data = 'bbbbbb'
# token = s.dumps(data).decode()
# 转成字符串数据
# print(token) # eyJhbGciOiJIUzUxMiIsImlhdCI6MTYzMDI1MzUzNSwiZXhwIjoxNjMwMjU3MTM1fQ.ImJiYmJiYiI.v1vEbaPcM3-5dsfSv9ORvej0nrbaVz12gGycU-zLtTisjZNJz5e_mCd10KT8shE7bdloaczAUf4gCBDP7kq_ww
data1 = s.loads("eyJhbGciOiJIUzUxMiIsImlhdCI6MTYzMDI1MzUzNSwiZXhwIjoxNjMwMjU3MTM1fQ.ImJiYmJiYiI.v1vEbaPcM3-5dsfSv9ORvej0nrbaVz12gGy"
"cU-zLtTisjZNJz5e_mCd10KT8shE7bdloaczAUf4gCBDP7kq_ww" )
print(data1)
# bbbbbb