import base64 msg = '123456' msg = msg.encode('utf-8') # 加密 passwd = base64.b64encode(msg) print(passwd) # b'MTIzNDU2' # 解密 res = base64.b64decode(passwd) result = res.decode('utf-8') print("res:",result) # 123456