Hashlib is a security hash and message digest that provides a number of different cryptographic algorithm interfaces, such as SHA1, SHA224, SHA256, SHA384, SHA512, MD5, and so on.
Common Properties
hashlib.algorithms
List all encryption algorithms
h.digest_size
The size of the resulting hash byte.
h.block_size
The size of the hash inner block
Common Methods
hash.new([arg])
Creates a hash object that specifies the encryption mode
hash.update(arg)
Updates a hash object with a string parameter. If the same hash object calls the method repeatedly, M.update (a); M.update (b) equivalent to M.update (A+B)
hash.digest()
Returns the digest as a binary data string value.
hash.hexdigest()
Returns a summary, as a hexadecimal data string value
hash.copy()
Copy
Code Instance
import hashlibmd5 = hashlib.md5() md5.update("I am Sin_Geek") print md5.digest() printprint‘block_size:‘, md5.block_sizeprint‘digest_size:‘, md5.digest_size
import hashlibprint‘-‘25‘更简洁版本‘‘-‘25print hashlib.new("md5""I am Sin_Geek").hexdigest()
"I am Sin_Geek"print hashlib.md5(a).hexdigest()print hashlib.sha1(a).hexdigest()print hashlib.sha224(a).hexdigest()print hashlib.sha256(a).hexdigest()print hashlib.sha384(a).hexdigest()print hashlib.sha512(a).hexdigest()
Python Module Learning Note--hashlib