python中base64的encode()与decode()

林弘文
2023-12-01

1、encode() 用来将字符串转化为二级制格式的数据,decode() 将二进制的数据转化为字符串

import base64


host_id = [{'password': 'aUhDSCZXUiN4ITVn', 'host_ip': '0.0.0.0',
           'username': 'zbc'}]

print(host_id[0]["password"])  # aUhDSCZXUiN4ITVn
print(host_id[0]["password"].encode()) # b'aUhDSCZXUiN4ITVn'
print(base64.b64decode(host_id[0]["password"])) # b'iHCH&WR#x!5g'
print(base64.b64decode(host_id[0]["password"].encode()).decode()) # iHCH&WR#x!5g

base64转码,解码网址:https://tool.oschina.net/encrypt?type=3

 类似资料: