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

一、Python Base64编码Python中进行Base64编码和解码要用base64模块,代码示例:#-*- coding: utf-8 -*-import base64str = cnblogsstr64 = base64.b64encode(str)print str64 #Y25ibG9ncw==print base64.b64decode(str64) #cnblogs二、MD5#Python 2.ximport

str = <span style=”color: #800000;”>'<span style=”color: #800000;”>cnblogs<span style=”color: #800000;”>'<span style=”color: #000000;”>
str64 =<span style=”color: #000000;”> base64.b64encode(str)
<span style=”color: #0000ff;”>print str64 <span style=”color: #008000;”>#<span style=”color: #008000;”>Y25ibG9ncw==
<span style=”color: #0000ff;”>print base64.b64decode(str64) <span style=”color: #008000;”>#<span style=”color: #008000;”>cnblogs

二、MD5

hashlib.md5(<span style=”color: #008000;”>#<span style=”color: #008000;”>Python 3.x
<span style=”color: #0000ff;”>import<span style=”color: #000000;”> hashlib
<span style=”color: #0000ff;”>print(hashlib.md5(<span style=”color: #800000;”>”<span style=”color: #800000;”>whatever your string is<span style=”color: #800000;”>”.encode(<span style=”color: #800000;”>'<span style=”color: #800000;”>utf-8<span style=”color: #800000;”>’)).hexdigest())

作者: dawei

【声明】:滨州站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。

为您推荐

联系我们

联系我们

0577-28828765

在线咨询: QQ交谈

邮箱: xwei067@foxmail.com

工作时间:周一至周五,9:00-17:30,节假日休息

返回顶部