一、什么是base64?
Base64是一种用64个字符来表示任意二进制数据的方法。
Base64是一种基于64个可打印字符来表示二进制数据的表示方法。由于2^6=64,所以每6个比特为一个单元,对应某个可打印字符。
二、base64简单运用
1.python3.8环境使用
首先安装好相应的库:
命令 pip install pybase64
然后导入 base64模块
1:示例代码
加密和解码运用
用到了base64.b64deocde()和base64.b64encode
base64.b64deocde()将base64编码的bytes类型进行解码,返回解码后的bytes类型,
base64.b64encode()将bytes类型数据进行base64编码,返回编码后的bytes类型
basejie=input("请输入要解码内容:")
##base64.b64deocde()将base64编码的bytes类型进行解码,返回解码后的bytes类型
decodestr = base64.b64decode(basejie)
a=decodestr.decode('utf-8')
print("解码结果:"+a)
jiami=input("输入加密内容:")
##base64.b64encode()将bytes类型数据进行base64编码,返回编码后的bytes类型
b= base64.b64encode(jiami.encode('utf-8'))
print("\n")
print("加密内容如下:")
print(b)
2:运行结果
输出结果中:b' '中间的内容为加密结果
即 6Ium6YC856iL5bqP5ZGY