#-*-coding:utf-8-*-"""Python's MD5 SHA1 module"""ImportHashlib#Examples of MD5m =hashlib.md5 () m.update (b"Hello 123") M.update (b"Hello 456")Print(M.digest ())#byte stringPrint(M.hexdigest ())#stringPrint(m.digest_size)# -Print(m.block_size)# -#can also be processed at oncePrint(HASHLIB.MD5 (b"Hello 123 Hello 456"). Hexdigest ())"""module function hashlib.new (Name[,data]) name: The name of the algorithm: Byte data hashlib.algorithms_guaranteed All platforms supported by the algorithm {' SHA1 ', ' sha256 ', ' sha384 ', ' MD5 ', ' sha512 ', ' sha224 '}hashlib.algorithms_available returns the available algorithm for Python, which can be used for new (), and guaranteed is a subset of it {' RIPEMD160 ' , ' SHA1 ', ' sha256 ', ' SHA256 ', ' sha ', ' dsaencryption ', ' MD5 ', ' SHA224 ', ' SHA384 ', ' Dsa-sha ', ' Dsawithsha ', ' sha224 ', ' MD4 ', ' MD4 ', ' whirlpool ', ' SHA ', ' sha384 ', ' ripemd160 ', ' MD5 ', ' SHA1 ', ' sha512 ', ' DSA ', ' SHA512 ', ' Ecdsa-with-sha1 '}hash object Properties ha Sh.digest_size the size of the result hash.block_size block size Hash.name name Hash.update (ARG) See Example Hash.digest () byte string hash.hexdigest () String Hash.copy () returns a copy of the hash object for password encryption Hashlib.pbkdf2_hmac (hash_name, password, salt, iterations, Dklen=none) hash_name Algorithm name password The password salt to encrypt is recommended for 16 bytes or longer iterations iterations, depending on the algorithm and computational power, the Dklen result length return value is a byte string"""#Test Iteration Time#100000 0.0625 Second results#1000000 0.63 A little card, please .#10000000 6.2 unacceptable#...#10000000000 Maximum value exceededImportBinascii fromDatetimeImportDatetimet1=DateTime.Now () DK= Hashlib.pbkdf2_hmac ('MD5'B'Password'B'Salt', 100000) T2=DateTime.Now () T= (t2-t1). Seconds + (T2-T1). microseconds/1000000Print(t) m=binascii.hexlify (DK)Print(m)
Python's Hashlib module