(a) MD5 value of the string
Import hashlib # imports the function module, this module has md5,sha1,sha256 etc method m = hashlib.md5 () # Declares an object m.update (b'Hello python' # Specifies a string with the object's Update method, and the preceding B is converted to binary, otherwise it cannot be displayed. Print(M.hexdigest ()) # uses the object's Hexdigest () method for hexadecimal display.
(ii) The MD5 value of a file
ImportHashlib#Import the function module, this module has md5,sha1,sha256 and so on methodm = Hashlib.md5 ()#declares a MD5 objectP='/home/jm/pgadmin.log' #Specify a filef = open (P,'RB')#open a file in binary read-only mode to generate a file objectstr = f.read (8089)#reads 8089 lines of content, which is the entire file for small filesm.update (str)#specifies a string with the Update method of the MD5 object, and the preceding B is converted to binary, otherwise it is not displayed. Print(M.hexdigest ())#Use the Hexdigest () method of the MD5 object for hexadecimal display.
Python asks for MD5 value