Tag: class converts characters by calculation data Date upd Update div
Python's hashlib provides a common digest algorithm, such as MD5,SHA1 and so on.
What is a digest algorithm? Abstract the algorithm is also called hash algorithm and hashing algorithm. It uses a function to convert any length of data into a fixed length data string (usually represented by a 16-binary string).
Abstract the algorithm is to calculate the fixed-length summary digest by the Digest function f () to the data of arbitrary length, in order to find out whether the original data has been tampered with.
Abstract the algorithm can point out whether the data has been tampered with, because the digest function is a one-way function, it is easy to calculate f (data), but it is very difficult to digest data by using it. Also, making a bit change to the original data will result in a completely different summary of the calculations.
MD5 is the most common digest algorithm and is fast enough to generate a fixed byte of bytes, typically represented by a 32-bit 16 binary string
The result of the SHA1 is a bit byte, which is usually represented by a 40-bit 16 binary string. Algorithms that are more secure than SHA1 are SHA256 and SHA512, but the more secure the algorithm is, the slower it is, and the longer the digest length.
We take the abstract algorithm MD5,SHA1 as an example:
Import hashlibmd5 = Hashlib.md5 () md5.update (' Esrdtfhij '. Encode (' Utf-8 ')) print (Md5.hexdigest ()) # B853c213f701e054bca65bb96fb461ebsha = HASHLIB.SHA1 () sha.update (' Esrdtfhij '. Encode (' Utf-8 ')) print (Sha.hexdigest () ) # 6f0b74185f30b1e1cf8e4ba355d9774ab4671295
Python module Hashlib