您的位置:首页 > 编程语言 > Python开发

python学习笔记十七:base64及md5编码

2015-04-16 19:11 274 查看

一、Python Base64编码

Python中进行Base64编码和解码要用base64模块,代码示例:

#-*- coding: utf-8 -*-
import base64

str = 'cnblogs'
str64 = base64.b64encode(str)
print str64                     #Y25ibG9ncw==
print base64.b64decode(str64)   #cnblogs


二、MD5

#Python 2.x
import hashlib
print hashlib.md5("whatever your string is").hexdigest()

#Python 3.x
import hashlib
print(hashlib.md5("whatever your string is".encode('utf-8')).hexdigest())
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: