Python3 MD5 Encryption

Source: Internet
Author: User
Tags md5 encryption

Import Hashlib

user = ' Jointwisdom '
PWD = ' zhonghui123 '

m2 = hashlib.md5 ()
M2.update (Pwd.encode ("Utf-8")) #参数必须是byte类型, otherwise reported unicode-objects must be encoded before hashing error
Print (M2.hexdigest ())


# But what about the Chinese string MD5?
# Chinese characters in Python are in Unicode, the same string in different coding system has different values, so before the hash to encode, personal advice to gb2312, because the contrast found that The MD5 value calculated by one of the tools I downloaded is the same as the MD5 value calculated after the gb2312 code. (! Online MD5 a lot of tools, is not all the MD5 tools are such, not to research, interested can study it
# [Python] view plain copy print?
# import Hashlib
# data= ' I am '
# m = hashlib.md5 (Data.encode (encoding= ' gb2312 '))
# Print (M.hexdigest ())

Python3 MD5 Encryption

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.