Python implements MD5 encryption

Source: Internet
Author: User
Tags md5 encryption
Implementation of MD5 encryption in Python is done through hashlib. Before the presentation, we created a piece of text to encrypt the data. As shown below: hashlib_data.py

#--encoding= ' Utf-8 '--

Import Hashlib

Lorem= "" "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donecegestas, enim et consectetuer ullamcorper, lectus ligula rutrum leo,a elementum elit tortor eu quam. Duis tincidunt nisi ut ante. Nullafacilisi. Sed tristique eros eu libero. Pellentesque Velarcu. Vivamus purus Orci, iaculis ac, suscipit sit amet, Pulvinar eu,lacus. Praesent placerat tortor sed nisl. Nunc blandit diam Egestasdui. Pellentesque habitant morbi tristique senectus et netus etmalesuada fames ac turpis egestas. Aliquam Viverra Fringillaleo. Nulla feugiat augue eleifend Nulla. Vivamus Mauris. Vivamus Sedmauris in Nibh placerat egestas. Suspendisse Potenti. Maurismassa. Ut eget velit auctor tortor blandit Sollicitudin. Suspendisseimperdiet Justo. """

Using MD5 for encryption is straightforward as long as you call the MD5 encryption algorithm in HASHLIB:

#--encoding= ' Utf-8 '--

Import Hashlib from Hashlib_data

Import Lorem

H=HASHLIB.MD5 ()

H.update (Lorem)

Print H.hexdigest ()

H=HASHLIB.MD5 () is used to create MD5 cryptographic objects;

H.update (Lorem) is the Lorem character is encrypted with the MD5 algorithm. The output results are as follows:

913fa23cc9326eb26f62859c9feed3e4

  • 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.