Title

python调包——hashlib加密

python调包——hashlib加密

#加密 md5 sha1 sha256 sha512

import hashlib

msg ="hello world"

md5 = hashlib.md5(msg.encode('utf-8'))#之所以选择用utf-8对msg进行编码,是因为考虑到了msg里面可能出现中文的形式
print(md5)
#<md5 _hashlib.HASH object @ 0x000001FB772F1B30> 单纯只是一个md5类型的hash对象
r = md5.hexdigest()#十六进制消化?
print(r)
print(len(r))
#5eb63bbbe01eeed093cb22bb8f5acdc3
#32

sha1 = hashlib.sha1(msg.encode('utf-8')).hexdigest()
print(sha1)
print(len(sha1))
#2aae6c35c94fcfb415dbe95f408b9ce91ee846ed
#40

sha256 = hashlib.sha256(msg.encode('utf-8')).hexdigest()
print(sha256)
print(len(sha256))
#b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9
#64

sha512 = hashlib.sha512(msg.encode('utf-8')).hexdigest()
print(sha512)
print(len(sha512))
#309ecc489c12d6eb4cc40f50c902f2b4d0ed77ee511a7c7a9bcd3ca86d4cd86f989dd35bc5ff499670da34255b45b0cfd830e81f605dcf7dc5542e93ae9cd76f
#128
posted @ 2021-03-01 23:34  BeautifulWater  阅读(91)  评论(0编辑  收藏  举报