1 import hmac 2 import os 3 c = os.urandom(24) # 返回一个随机的32字节的二进制数,可以应用于密码相关的方面 4 name = b‘liuyk‘ 5 h = hmac.new(name,c) 6 digest = h.digest() # This returns a string containing 8-bit data. The object is 7 # not altered in any way by this function; you can continue 8 # updating the object after calling this function. 9 h.update(b‘hahaha‘) 10 print(digest) 11 print(h.digest()) 12 print(h.hexdigest(),len(h.hexdigest()))