Hashlib module of common modules
For cryptographic related operations, the 3.x replaces the MD5 module and the SHA module, mainly providing SHA1, SHA224, SHA256, SHA384, SHA512, MD5 algorithm
Import= md5.new () hash.update ('admin')Print Hash.hexdigest ()
md5-Waste
Import= sha.new () hash.update ('admin')print Hash.hexdigest ()
sha Waste
Import Hashlib # ######## MD5 ######## hash = HASHLIB.MD5 () hash.update (' admin ') print hash.hexdigest () # ######## SHA1 # # # # # # # hash = HASHLIB.SHA1 () hash.update (' admin ') print hash.hexdigest () # ######## sha256 ######## hash = hashlib.sha256 () ha Sh.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 ()
Although the above encryption algorithm is still very strong, but the time has the flaw, namely: through the collision library can reverse the solution. Therefore, it is necessary to add a custom key to the encryption algorithm to do encryption.
Import Hashlib # ######## MD5 ######## hash = hashlib.md5 (' 898oafs09f ') hash.update (' admin ') print hash.hexdigest ()
Not enough to hang? Python also has an HMAC module that internally creates keys and content for us to process and then encrypt
Import Hmach = hmac.new (' Wueiqi ') h.update (' Hellowo ') print h.hexdigest ()
No more!!!
1 ImportHashlib2 3m =hashlib.md5 ()4M.update (b"Hello")5M.update (b"It ' s me")6 Print(M.digest ())7M.update (b"It ' s been a long time since last time we ...")8 9 Print(M.digest ())#2 binary format hashTen Print(Len (M.hexdigest ()))#16 binary format hash One " " A def digest (self, *args, **kwargs): # Real Signature Unknown - "" " Return the Digest value as a string of binary data. " " - Pass the - def hexdigest (self, *args, **kwargs): # Real Signature Unknown - "" " Return the Digest value as a string of hexadecimal digits. " "" " - Pass + - " " + ImportHashlib A at ######### MD5 ######## - -hash =hashlib.md5 () -Hash.update ('Admin') - Print(Hash.hexdigest ()) - in ######### SHA1 ######## - tohash =hashlib.sha1 () +Hash.update ('Admin') - Print(Hash.hexdigest ()) the * ######### sha256 ######## $ Panax Notoginsenghash =hashlib.sha256 () -Hash.update ('Admin') the Print(Hash.hexdigest ()) + A the ######### sha384 ######## + -hash =hashlib.sha384 () $Hash.update ('Admin') $ Print(Hash.hexdigest ()) - - ######### sha512 ######## the -hash =hashlib.sha512 ()WuyiHash.update ('Admin') the Print(Hash.hexdigest ())
View Code
Read more about md5,sha1,sha256 and other introductory articles here https://www.tbs-certificates.co.uk/FAQ/en/sha256.html
Python Learning Notes-basic "Sixth Week"--hashlib module