hashlib模块------->加密

#_author:star
#date:2019/11/5
#hashlib模块------->加密
import hashlib
m=hashlib.md5()
print(m)#<md5 HASH object @ 0x00C9A8A8>
#'abc'>>>>>>>>>>>>>>>>>>>>>>md5>>>>>>>>>>>>>>>>>>>>>>>>>>>>'ashgshdgjsjqgjajsjax'
m.update('hello yuwei'.encode('utf-8'))# 将Unicode转换为utf-8,通过update进行明文转换
print(m.hexdigest())# 转换后的结果 通过 m.hexdigest将其取出来(为一个16进制的值) ------>adac1a59ffaf558c881430955f96781a
m.update('star'.encode('utf8'))
print(m.hexdigest())#58fba085bf78415982eca5cb8f064d5a
#验证两次添加的字符串是否有关联
m2=hashlib.md5()
m2.update('hello yuweistar'.encode('utf8'))
print(m2.hexdigest())#58fba085bf78415982eca5cb8f064d5a
#高级加密 sha3_256()
s=hashlib.sha3_256()
s.update('yuweistarl'.encode('utf8'))
print(s.hexdigest())#73bf5625d005c4a5e8c6c5d2813a475e03f61efeb553efd42128c766d6de5342
posted @ 2019-11-06 18:23  Stary_tx  阅读(135)  评论(0编辑  收藏  举报