Hashlib is a security hash and message digest that provides several different cryptographic algorithm excuses, such as SHA1, SHA224, SHA256, SHA384, SHA512, MD5, and so on.
ImportHASHLIBM= HASHLIB.MD5 ()#Create a Hash object, MD5: (message-digest algorithm 5) message digest algorithm, to obtain a 128-bit cipherPrintM#<md5 HASH Object @ 000000000254adf0>M.update ('Beginman')#update Hash object with string parameterPrintM.digest ()#returns the digest as a binary data string valuePrintM.hexdigest ()#returns a hexadecimal numeric string 0b28251e684dfbd9102f8b6f0281c0c5PrintM.digest_size# -PrintM.block_size# -
H = hashlib.new ('MD5')PrintH#<md5 HASH Object @ 000000000260bdb0>H2 = Hashlib.new ('ripemd160',' What')PrintH2#<ripemd160 HASH Object @ 000000000271b9f0>H.update ('Beginman')PrintH.hexdigest ()#666fc5baa93a7fb207c5bfff03b67732#equivalents =hashlib.md5 () s.update ('Beginman')PrintS.hexdigest ()#666fc5baa93a7fb207c5bfff03b67732PrintH2.hexdigest ()#9c1185a5c5e9fc54612808977ee8f548b2258d31
# Properties print hashlib.algorithms #(' MD5 ', ' SHA1 ', ' sha224 ', ' sha256 ', ' sha384 ', ' sha512 ') List all cryptographic algorithms print h.digest_size #print h.block_size #Theinternal block size of the hash algorithm in bytes.
Common methods
Hash.update (ARG)
Update the hash object with a string argument, m.update (a) if the same hash object repeats the method call; M.update (b) is equivalent to m.update (a+b).
Hash.digest ()
Returns a digest, as a binary data string value,
Hash.hexdigest ()
Returns a summary, as a hexadecimal data string value,
Import'/beginman/'== '%s%s ' % (Key_value,now.strftime ("%y%m%d"= M.hexdigest ()print#8db42d3e90b41105ed061b8347a7c850
Python module Hashlib (provides multiple different encryption algorithms)