python base64加密解密:
import base64
import StringIO
a = "this is a test"
b = base64.encodestring(a) # 对字符串编码
print b
print base64.decodestring(b) # 对字符串解码
c = StringIO.StringIO()
c.write(a)
d = StringIO.StringIO()
e = StringIO.StringIO()
c.seek(0)
base64.encode(c, d) # 对StringIO内的数据进行编码
print d.getvalue()
d.seek(0)
base64.decode(d, e) # 对StringIO内的数据进行解码
print e.getvalue()
a = "this is a +test"
b = base64.urlsafe_b64encode(a) # 进行url的字符串编码
print b
print base64.urlsafe_b64decode(b)
本文介绍并演示了使用 Python 的 base64 模块进行字符串的编码和解码过程。包括标准 Base64 编码、Base64 解码、针对 URL 安全的 Base64 编码及解码操作。通过具体的代码示例,展示了如何对普通字符串和使用 StringIO 存储的数据进行编码与解码。
1169

被折叠的 条评论
为什么被折叠?



