python中base64加密解密 发表于 2019-04-29 | 分类于 python | 评论数: | 阅读次数: 本文字数: 1.3k | 阅读时长 ≈ 0:01 利用python对字符串或者文件进行base64位加密解密。 内容提示 字符加密 字符串解密 文件加密 文件解密 代码1234567891011121314151617181920212223242526272829303132333435363738#!/usr/bin/env python # -*- coding:utf-8 -*-"""info"""import base64def encode_str(strs): #加密 # s1='40ab6290da9a5c2ddd43760511a01e8af21b5187' encodestr = base64.b64encode(strs.encode('utf-8')) enstrs=str(encodestr,'utf-8') print(enstrs) return enstrsdef decode_str(enstrs): #解密 # enstr='5pyJ5b+D55qE5L2g77yM55yL5Yiw5LqG5pyJ5b+D55qE5oiR77yM5LiN5b6X5LiN6K+05piv5LiA56eN57yY5YiG77yM5aaC5p6c5L2g5Zyo5aWL5paX77yM5Yqg5rK577yM54ix6Ieq5bex77yM54ix5pyL5Y+L77yM54ix5a625Lq644CC' strs=str(base64.b64decode(enstrs[:].encode('utf-8')),'utf-8') print(strs) return strsdef endcode_file(fn): # 文件转化为base64 f = open(fn, 'rb') fnb64 = base64.b64encode(f.read()).decode('utf-8') return fnb64def decode_file(fn): # 文件转化为base64 f = open(fn, 'rb') fnb64str = str(base64.b64decode(f.read()).ecode('utf-8'),'utf-8') return fnb64strif __name__=="__main__": pass 网络工具 的确最好用https://base64.us/ http://tool.oschina.net/encrypt?type=3 图片转64位http://imgbase64.duoshitong.com/ 本文作者: WQian 本文链接: https://wqian.net/blog/2019/0429-index.html 版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!