Python Module Learning Note--hashlib

Source: Internet
Author: User

Hashlib is a security hash and message digest that provides a number of different cryptographic algorithm interfaces, such as SHA1, SHA224, SHA256, SHA384, SHA512, MD5, and so on.

Common Properties

hashlib.algorithms
List all encryption algorithms

h.digest_size
The size of the resulting hash byte.

h.block_size
The size of the hash inner block

Common Methods

hash.new([arg])
Creates a hash object that specifies the encryption mode

hash.update(arg)
Updates a hash object with a string parameter. If the same hash object calls the method repeatedly, M.update (a); M.update (b) equivalent to M.update (A+B)

hash.digest()
Returns the digest as a binary data string value.

hash.hexdigest()
Returns a summary, as a hexadecimal data string value

hash.copy()
Copy

Code Instance
import hashlibmd5 = hashlib.md5() md5.update("I am Sin_Geek")  print md5.digest()  printprint‘block_size:‘, md5.block_sizeprint‘digest_size:‘, md5.digest_size

import hashlibprint‘-‘25‘更简洁版本‘‘-‘25print hashlib.new("md5""I am Sin_Geek").hexdigest()

"I am Sin_Geek"print hashlib.md5(a).hexdigest()print hashlib.sha1(a).hexdigest()print hashlib.sha224(a).hexdigest()print hashlib.sha256(a).hexdigest()print hashlib.sha384(a).hexdigest()print hashlib.sha512(a).hexdigest()

Python Module Learning Note--hashlib

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.