Python asks for MD5 value

Source: Internet
Author: User
Tags sha1

(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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.