[code] 编码-隐藏密码

import json
import base64

# 输入
x = dict(a=1, b='555', name='中文')

# 编码
y = json.dumps(x, indent=2).encode('utf-8')
with open('b64.txt', 'wb') as fp:
    fp.write(base64.b64encode(y))

# 解码
with open('b64.txt', 'rb') as fp:
    c = fp.read()
x = json.loads(base64.b64decode(c))
  • 单向加密
import hmac
y = hmac.new(b"secretKey", b"secretMessageToHash", digestmod='sha256').hexdigest()

--- 她说, 她是仙,她不是神
原文地址:https://www.cnblogs.com/bregman/p/15152900.html