base64编码与base64解码
base64编码与解码
# md5固定长度,不可反解
# base64不定长度,可以反解
示例
import base64
import json
# 编码
beast_dict = {"username": "surpass", "password": "123456", "gender": "male", "age": 18}
beast_str = json.dumps(beast_dict)
ret = base64.b64encode(beast_str.encode('utf-8')) # 里面需要是一个byte格式
print(ret)
# 解码
ret2 = base64.b64decode(ret)
print(ret2)
打印结果
[root@alisurpass ~]# python wptest.py
b'eyJ1c2VybmFtZSI6ICJzdXJwYXNzIiwgInBhc3N3b3JkIjogIjEyMzQ1NiIsICJnZW5kZXIiOiAibWFsZSIsICJhZ2UiOiAxOH0='
b'{"username": "surpass", "password": "123456", "gender": "male", "age": 18}'