Python Hashlib Notes

Source: Internet
Author: User

Tag:his   sha-1   nts    not    --    microsoft   exce   mic   ade   

#python3.4
hashlib module-a Common interface to many hash functions.
hash.digest ()-Return the Digest of the The data passed to the update () method is far. This was a bytes object of size digest_size which may contain bytes in the whole range from 0 to 255.
hash.hexdigest ()-Like Digest () Except the digest is returned as a string object of double length, containing only hexadecimal digits. This is used to exchange, the value safely in email, or other non-binary environments.


Note 1:python 3 because the default is Unicode so arg in Update (ARG) if it is a string, you need to start with B, such as B "Hello world!!".
NOTE 2: MD5 For example, and checksum for 128bit data, corresponding to 16Byte data. However, this 16Byte cannot be represented directly by ASCII (storage, communication, etc.).
Therefore, using hexdigest to divide 128bit into 32 4bit data, 4bit data with Hex (0~9,A~F) ASCII representation. This is good for a lot of communication protocols, but also the wind convenient for people to read and compare.

MD5--128bit,sha-1--160bit, SHA-256--256bit, SHA-512--512bit

Example:
>>>import Hashlib
>>>HASHLIB.MD5 (b "Hello"). Digest ()
B '][email protected]*\xbck*v\xb9q\x9d\x91\x10\x17\xc5\x92 '
>>>HASHLIB.MD5 (b "Hello"). Hexdigest ()
' 5d41402abc4b2a76b9719d911017c592 '

1. Split the hexdigest as follows:
5d 2a BC 4b 2a B9-9d c5 92

2, every 2 for hex conversion to hex (which is greater than 0x80 of the conversion, some of the 0x0~0x7f also need to transfer. Can get
B '] A @ * \XBC K * v \xb9 q \x9d \x91 \x10 \x17 \xc5 \x92. and digest (right up).

Python Hashlib Notes

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.