# Import module hashlib Import hashlib # obtain MD5 objects # unsalted operation # MD5 = hashlib.md5 () # salt operating MD5 = hashlib.md5 ( ' wenwe1i ' .encode ( " UTF8 " )) # acquired require encryption field md5.update ( ' How to use MD5 in Python hashlib? ' .encode ( " utf8 " )) Print (md5.hexdigest ())
class Md5(object): def __init__(self, salt, content): self.salt = salt self.content = content def encryption(self): import hashlib md5 = hashlib.md5(self.salt.encode("utf8")) md5.update(self.content.encode("utf8")) ret = md5.hexdigest() return ret ret = Md5('wenwe1i', 'how to use md5 in python hashlib?') ret.encryption()