Novice Learning Python (eight) encryption module (MD5 encryption)

Source: Internet
Author: User
Tags md5 encryption

 because the MD5 module was removed in the Python3
MD5 operation with Hashlib module in Python3

Import Hashlib

m=hashlib.md5 () #创建MD5对象
passwd= ' aaa123 ' #待加密密码
m.update (Passwd.encode ()) #不能直接对字符串加密, first convert the string to bytes type
print (M.hexdigest ()) #打印加密结果
#md5加密是不可逆的

= = Encryption function = = =
def my_md5 (str):
Import Hashlib
New_str=str.encode () #把字符串转成bytes类型
m =hashlib.md5 () #实例化MD5对象
m.update (new_str) #加密
return m.hexdigest () #获取结果返回

Print (MY_MD5 (' 123 '))

Novice Learning Python (eight) encryption module (MD5 encryption)

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.