base64码
Base64是一种基于64个可打印字符来表示二进制数据的表示方法,常用于在通常处理文本数据的场合,表示、传输、存储一些二进制数据,包括MIME的电子邮件及XML的一些复杂数据。对其进行加密,解密。
例如:对图片和数字加密
import base64
str1 = ‘13733177926’
content_b64_bytes = base64.b64encode(str1.encode(encoding= ’ utf-8’))
print(content_b64_bytes)
# b 'MTM3HZMxNZc5MjY='本应看到b ‘\x3f\xd0’ pycharm自动转换了。
content_b64_str = content_b64_bytes.decode(encoding= 'ascii ')
print('我的绿色软件是: ',content_b64_str)
#图片
with open( ’ ./testimage.jpg’ , mode= 'rb ’ ) as f:
content_bytes = f.read()
content_b64_bytes = base64.b64encode(content_bytes)
content_b64_str = content_b64_bytes.decode(encoding= ‘ascii’)
print(content_b64_str)