Python hashlib module

Source: Internet
Author: User

Hashlib Effect:

Encrypt plaintext into ciphertext, there are two methods of encryption Md5,sha

Example Walkthrough:

1.md5 method

1 Import Hashlib 2 3 hash = hashlib.md5 ()4 hash.update ("helloWorld". Encode ( ' Utf-8 ' ))5Print(Hash.hexdigest ())

Printing results:

5eb63bbbe01eeed093cb22bb8f5acdc3

Note:

Python3 the default encoding format is Unicode,update method only accepts bytes, so encode decoding is required

2.sha method

There are many methods for Sha, and the latter is more and more complex, the lower the efficiency of operation. General application sha256

1 hash = hashlib.sha256 ()2 hash.update ("helloWorld". Encode ( ' Utf-8 ' ))3print(Hash.hexdigest ())

Printing results:

B94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9

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.