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