Python3 md5加密
2016-12-14 12:11
405 查看
import hashlib
user = 'jointwisdom'
pwd = 'zhonghui123'
m2 = hashlib.md5()
m2.update(pwd.encode("utf-8"))#参数必须是byte类型,否则报Unicode-objects must be encoded before hashing错误
print(m2.hexdigest())
# 但是对中文字符串md5怎么办?
# 中文字符在Python中是以unicode存在的,同一个字符串在不同的编码体系下有不同的值,所以在hash前要进行编码,个人建议转为gb2312,因为对比发现,我下载的一个工具算出的md5值是与gb2312编码后算出的md5值一样。(!网上md5的工具很多,是不是所有的md5工具都是这样的,未去考证,有兴趣的可以研究一下)
# [python] view plain copy print?
# import hashlib
# data='我是'
# m = hashlib.md5(data.encode(encoding='gb2312'))
# print(m.hexdigest())
相关文章推荐
- Python hashlib模块 (主要记录md5加密)
- python MD5加密
- 关于python2.7的md5加密遇到的问题(TypeError: Unicode-objects must be encoded before hashing)
- Python加密—MD5加密
- python的md5加密
- Python hashlib模块 (主要记录md5加密)
- python-MD5加密
- python文件的md5加密方法
- python2-3 md5加密 方法
- Python hashlib模块 (主要记录md5加密)
- Python使用MD5加密字符串示例
- Python-保存MD5加密随机产生的账号密码
- python md5加密中文
- python进行md5加密
- python md5加密
- 【python】Python字符串md5加密
- Python使用MD5加密字符串示例
- python tkinter MD5加密
- python 之MD5加密
- python实现MD5加密