Django 加密解密

 django.core.signing模块

复制代码
加密:
>>> from django.core.signing import Signer
>>> signer = Signer()
>>> passwd = signer.sign("123456")
>>> passwd
'123456:fgIOAPqsDczcp8QFnZ7dVkOvEE8'
>>> type(passwd)
<class 'str'>

解密:
>>> restore = signer.unsign(passwd)
>>> restore
'123456'
复制代码

给字典类型数据加密,解密

列表、元组同样加密解密

>>> from django.core import signing
>>> value = signing.dumps({"name": "vv"})
>>> value
'eyJuYW1lIjoidnYifQ:1lRtRz:ZJtFIbKWjb75PZROIW1o4dmuWqE'
>>>
>>> signing.loads(value)
{'name': 'vv'}

参考:

https://wiki.jikexueyuan.com/project/django-chinese-docs-1.8/8-5-cryptographic-signing.html

posted @   半日闲1  阅读(554)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示