Python MD5 encryption and pythonmd5 Encryption

Source: Internet
Author: User

Python MD5 encryption and pythonmd5 Encryption

The following describes how to use the Python built-in hash library to encrypt strings using MD5:

First, import the modules required for MD5 encryption:

Import hashlib

Then create an md5 object:

M = hashlib. md5 ()

Input the string to be encrypted for MD5 encryption:

M. update ("str4MD5Encode ")

Then we can get the MD5-encrypted string:

EncodeStr = m. hexdigest () print encodeStr

Output result:

F8fd73cf519e6f11513d505b9dd33541

Of course, for code reuse, we can write these simple codes into a function. The input function is a string that requires MD5 encryption, and the output is the result obtained after MD5 encryption:

Import hashlibdef md5Encode (str): m = hashlib. md5 () m. update (str) return m. hexdigest ()



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.