python: hashlib 加密模块

加密模块hashlib

import  hashlib
m=hashlib.md5()
m.update(b'hello')
print(m.hexdigest()) #十六进制加密
m.update(b'world')
print(m.hexdigest()) #这个的加密是(b('helloworld'))
#5d41402abc4b2a76b9719d911017c592
#fc5e038d38a57032085441e7fe7010b0
s=hashlib.md5()
s.update(b'helloworld')
print(s.hexdigest()) #第二个值和第三个值相等
#除了md5的加密方式,还有其他的加密sha1,sha224,sha256,sha384,sha512
p=hashlib.sha256()
p.update('世界您好'.encode(encoding='utf-8'))
print(p.hexdigest())
#用法同md5
加密模块hashlib
hmac消息加密,比较快,双层加密
#hmac消息加密,比较快,双层加密
import hmac
d=hmac.new(b'nihao','放假了'.encode(encoding='utf-8'))
print(d.hexdigest())
print(d.digest())
hmac消息加密

 


posted @ 2016-10-25 23:32  梅子472  阅读(185)  评论(0编辑  收藏  举报