[nlp] base64编码解码:字符串编码为字符流

state_str = str(state)[2:-1].encode() 
import base64

#字符串编码为字节流

str = 'hello world'.encode(encoding='utf-8') # b'hello world'
state = base64.b64encode(str) # 加密 b'aGVsbG8gd29ybGQ='

state_byte = str(state)[2:-1].encode()

decode = base64.b64decode(state) # 解密 b'hello world'
decode = decode.decode(encoding='utf-8') # hello world


 

猜你喜欢

转载自blog.csdn.net/Trance95/article/details/131810485