Python计算hash值——hashlib模块

#python3.4

注意Python的版本2与3的区别

hashlib module - A common interface to many hash functions.

Hash objects have these methods:
 - update(arg): Update the hash object with the bytes in arg. Repeated calls
                are equivalent to a single call with the concatenation of all
                the arguments.

生成hash对象后,就可以用update方法对字符串进行md5加密的更新处理       
 - digest():    Return the digest of the bytes passed to the update() method
                so far.

 得到的bytes:b'\x8f\xe2\xf6\xf8Y4\x11\xff\xb2S+\x00-\nyv'
 - hexdigest(): Like digest() except the digest is returned as a unicode
                object of double length, containing only hexadecimal digits.  

 得到的unicode 8fe2f6f8593411ffb2532b002d0a7976

 hexdigest()常用
 - copy():      Return a copy (clone) of the hash object. This can be used to
                efficiently compute the digests of strings that share a common
                initial substring.

 

全文:http://blog.csdn.net/chaosju/article/details/42986463 //我用 digest函数,PyCharm控制台输出一串乱码。之后换了,用这个 hexdigest() 就输出真正的哈希码,即这种形式:9d5e54f12f3f4a8b6dd02439b1a3da144ce20e89

posted @ 2016-10-17 18:46  stma  阅读(3921)  评论(0)    收藏  举报