Python3 using Hashlib for encryption

Source: Internet
Author: User

Hashlib is a dedicated hash algorithm for the library, including MD5, SHA1, sha224, SHA256, sha384, sha512, the use of very simple, convenient.

MD5

The full name of MD5 is message-digest algorithm 5 (Information-Digest algorithm). 128-bit length. At present, MD5 is an irreversible algorithm.

It has high security. It corresponds to any string that can be encrypted into a unique fixed-length code.

SHA1

The full name of SHA1 is secure Hash algorithm (Secure Hash algorithm). SHA1 based on MD5, the data length is longer after encryption,

It produces a hash value of 160bit in length for inputs that are less than 264 in length. 32 more bits than MD5. Therefore, it is more secure than MD5, but SHA1 is slower than MD5.

Here's how to use the Hashlib:

1      2 ImportHashlib3 4A ="a test string"5 PrintHASHLIB.MD5 (Repr (a). Encode ('Utf-8'). Hexdigest ()6 PrintHASHLIB.SHA1 (Repr (a). Encode ('Utf-8'). Hexdigest ()7 Printhashlib.sha224 (Repr (a). Encode ('Utf-8'). Hexdigest ()8 PrintHASHLIB.SHA256 (Repr (a). Encode ('Utf-8'). Hexdigest ()9 Printhashlib.sha384 (Repr (a). Encode ('Utf-8'). Hexdigest ()Ten PrintHASHLIB.SHA512 (Repr (a). Encode ('Utf-8'). Hexdigest ()

Python3 using Hashlib for 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.