Python hashlib 无法打印

# !/user/bin/python
# -*- coding: utf-8 -*-

import hashlib

# 可提供MD5算法 , 防止内页被篡改 (若内页未被篡改, MD5的值是不变的)
m = hashlib.md5()
m.update(b"hello")
print(m.hexdigest())  # 生成md5值.
m.update(b"it's me")  # 不是用it's me 取代了hello, 而是加在了hello的后面, 所以md5值应该和直接写helloit's me的md5值一样.
print(m.hexdigest())
m.update(b"it's been a long time since we spoken...")
print(m.hexdigest())


m2 = hashlib.md5()
m2.update(b"helloit's me")
print(m.hexdigest())  # 为什么和第三句话的md5值一样, 不是应该和第二句话的md5值一样吗? TODO

s2 = hashlib.sha1
s2.update(b"helloit's me")
print(s2.hexdigest)


import hmac  # 双重加密
h = hmac.new("12345", "you are 250", encode(encoding="utf-8")) # 为什么不行?TODO
print(h.digest())
print(h.hexdigest())
原文地址:https://www.cnblogs.com/cheese320/p/9061122.html