首页 > 编程语言 > 详细

python hashlib模块

时间:2018-01-14 10:24:20      阅读:264      评论:0      收藏:0      [点我收藏+]

hashlib作用:

将明文加密成密文,有两种加密方法md5,sha

实例演练:

1.md5方法

1 import hashlib
2 
3 hash = hashlib.md5()
4 hash.update("hello world".encode(utf-8))
5 print(hash.hexdigest())

打印结果:

5eb63bbbe01eeed093cb22bb8f5acdc3

备注:

python3默认编码格式是unicode,update方法只接受bytes,所以需要进行encode解码

2.sha方法

技术分享图片

sha有很多种方法,后面算法越来越复杂,运算效率越低。一般应用sha256

1 hash = hashlib.sha256()
2 hash.update("hello world".encode(utf-8))
3 print(hash.hexdigest())

打印结果:

b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9

 

python hashlib模块

原文:https://www.cnblogs.com/qinyanli/p/8282347.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!