Base64专题---Python实现Base64加密和解密

algorain

Base加密方法很方便,在保存一些特别数据时可以直接调用方法进行加密和解密的操作,我会发一篇专门介绍base64原理的文章,有兴趣的可以先去查看。还有php和java的使用代码我都会贴在文章最后。

下面是使用python进行base64加密与解密的源码,使用时建议将代码写到一个函数里,方便使用的时候自己调用即可,记住值的传递与接收
1
2
3
4
5
6
7
8
9
10
11
12
13
import base64
#对字符串加密解密
string = "3423"
base64_encode_string = base64.encodestring(string)
print base64_encode_string
base64_decode_string = base64.decodestring(base64_encode_string)
print base64_decode_string
#当对文件整体进行加密或解密时使用encode
file_render = open('file1.txt','r')
file_write = open('file2.txt','w')
base64.encode(file_render,file_write)
file_render.close()
file_write.close()
我的其他两篇文章

》》》java中使用Base64加密解密的函数 》》》PHP实现base64加密和解密的方法 》》》

  • Title: Base64专题---Python实现Base64加密和解密
  • Author: algorain
  • Created at: 2017-02-04 00:53:47
  • Updated at: 2023-05-14 21:39:50
  • Link: http://www.rain1024.com/2017/02/04/python-article0016/
  • License: This work is licensed under CC BY-NC-SA 4.0.
 Comments
On this page
Base64专题---Python实现Base64加密和解密