Hashlib Module Hashlib module, mainly used for encryption-related operations.
In the Python3 version, instead of the MD5 and SHA modules, mainly provide SHA1, SHA224, SHA256, SHA384, SHA512, MD5 algorithm.
import hashlib m = hashlib. MD5() m. Update(b"Hello") m. Update(b"It ' s Me") print(m. Digest()) m. Update(b"It ' s been a long time since last time we ...") print(m. Digest()) #2进制格式hash Print(len(m. Hexdigest())) #16进制格式hash # ######## MD5 ########hash = hashlib. MD5() Hash. Update(' admin ') print(hash. Hexdigest()) # ######## SHA1 ######## hash = hashlib. SHA1() Hash. Update(' admin ') print(hash. Hexdigest()) # ######## sha256 ########hash = hashlib. sha256() Hash. Update(' admin ') print(hash. Hexdigest()) # ######## sha384 ########hash = hashlib. sha384() Hash. Update(' admin ') print(hash. Hexdigest()) # ######## sha512 ######## hash = hashlib. sha512() Hash. Update(' admin ') print(hash. Hexdigest())
Python Cryptographic Module Hashlib