import base64
def ToBase64(file, txt):
with open(file, 'rb') as fileObj:
image_data = fileObj.read()
base64_data = base64.b64encode(image_data)
fout = open(txt, 'w')
fout.write(base64_data.decode())
fout.close()
def ToFile(txt, file):
with open(txt, 'r') as fileObj:
base64_data = fileObj.read()
ori_image_data = base64.b64decode(base64_data)
fout = open(file, 'wb')
fout.write(ori_image_data)
fout.close()
ToBase64("./test01.docx",'desk_base64.txt') # 文件转换为base64
ToFile("./desk_base64.txt",'desk_cp_by_base64.docx') #base64转换成二进制文件
base64对文件加解密
最新推荐文章于 2024-07-02 17:07:34 发布