Python hashlib module

Source: Internet
Author: User

Function: can be used to encrypt. MD5, SHA1, SHA256, sha512

1>>>Importhashlib #导入hashlib加密模块2>>> m=hashlib.md5 () #定义一个md5对象3>>>Print(m)4<md5 Hash Object @ 0x7fb78f99c6c0> #输出对象m可以看出是一个md5 Hash5>>> M.update ("Hello World". Encode ('UTF8') #对hello World for MD5 encryption, character encoding using UTF8 format, and character encoding in Python3 by default in Unicode format. 6>>>7>>>Printm8<md5 HASH Object @ 0x7fb78f99c6c0>9>>>Printm.hexdigest () #以十六进制方式输出m, you will find that the characters inside are not more than F (Hex range). Ten5eb63bbbe01eeed093cb22bb8f5acdc3
>>> m.update (' Qiyuanchang '. Encode (' UTF8 ')) #这里的update是在上一次hello wold based on the underlying encryption, not a new encryption at a time.
>>> Print m.hexdigest ()
8e307de43044db33276a97776259562b
-
>>> m2=hashlib.md5 () #这里重新创建一个hash加密对象m2, the cryptographic characters are the same as the two operations above, and the results are the same after the encryption is found.
>>> m2.update ("Hello Worldqiyuanchang". Encode (' UTF8 '))
>>> print m2.hexdigest ()
8e307de43044db33276a97776259562b

Python hashlib module

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.