Encryption Algorithm Introduction Hash
- Hash, the general translation to do "hash", there is a direct transliteration of "hash" , is the arbitrary length of the input (also known as pre-mapping, pre-image), through the hash algorithm, transformed into a fixed-length output, the output is the hash value. This conversion is a compression map, that is, the space of the hash value is usually much smaller than the input space, the different inputs may be hashed to the same output, but not from the hash value to uniquely determine the input value.
- Simply, a function that compresses messages of any length to a message digest of a fixed length.
- Hash is mainly used in the field of information security encryption algorithm, he has a number of different lengths of information into a cluttered 128-bit encoding, called the hash value. It can also be said that the hash is to find a data content and data storage address mapping between
MD5 What is the MD5 algorithm?
- MD5 Message digest Algorithm (English: MD5 message-digest algorithm), a widely used cryptographic hash function, can produce a 128-bit hash value (hash value), Used to ensure complete consistency of information transmission. MD5 's predecessor was MD2, MD3 and MD4.
MD5 function
- Input any length of information, processed, output is 128 bits of information (digital fingerprint);
- Different inputs get different results (uniqueness);
Features of the MD5 algorithm
- Compressibility: Any length of data, the length of the calculated MD5 value is fixed
- Easy to calculate: It is easy to calculate the MD5 value from the original data
- Anti-modification: Make any changes to the original data, change the MD5 value generated by one byte will be very different.
- Strong anti-collision: Known raw data and MD5, it is very difficult to find a data with the same MD5 value (that is, falsification of data).
is the MD5 algorithm reversible?
- The reason why MD5 is not reversible is that it is a hash function, which uses the hash algorithm, and the part of the original information is lost during the calculation.
MD5 use
SHA-1
- Secure Hash algorithm is primarily applicable to digital signature algorithms (digitally Signature standard DSS) defined in digital Signature Algorithm DSA). For messages that are less than 2^64 bits in length, SHA1 produces a 160-bit message digest. When a message is received, this message digest can be used to verify the integrity of the data.
- Sha is a series of cryptographic hashing functions, designed by the National Security Agency, issued by the National Institute of Standards and Technology of the United States.
- As MD5 and SHA-1 in 2005 by the Shandong University Professor Xiao cracked, the scientists launched the SHA224, SHA256, SHA384, SHA512, of course, the longer the number of bits, the more difficult to crack, but also generate encrypted message digest takes longer. The most popular is the encryption algorithm is SHA-256.
Comparison of MD5 and SHA-1
- Since both MD5 and SHA-1 are developed from MD4, their structure and strength have many similarities, and the biggest difference between SHA-1 and MD5 is that the digest is 32 bits longer than the MD5 digest. For a brute force attack, any message that produces a digest equals the difficulty of a given digest: MD5 is a 2128 order of magnitude operation, and SHA-1 is a 2160 order of magnitude. The difficulty of generating two messages with the same digest: MD5 is 264 is an order of magnitude, and SHA-1 is 280 orders of magnitude operation. As a result, SHA-1 has a greater intensity of brute force attacks. However, because the SHA-1 cycle step is more than MD5 80:64 and the cache to be processed is 160 bits larger: 128 bits, SHA-1 runs slower than MD5.
Hashlib Module
- Hashlib is used to replace the MD5 and SHA modules after python3.x , and to make their APIs consistent.
- It is supported by OpenSSL and supports the following algorithms: MD5,SHA1, sha224, sha256, sha384, sha512
import hashlibm = hashlib.md5()m.update(b"Hello")m.update(b"It‘s me")print(m.digest())m.update(b"It‘s been a long time since last time we ...")print(m.digest()) #2进制格式hashprint(len(m.hexdigest())) #16进制格式hashimport hashlib# ######## md5 ########hash = hashlib.md5()hash.update(‘admin‘)print(hash.hexdigest())# ######## sha1 ########hash = hashlib.sha1()hash.update(‘admin‘)print(hash.hexdigest())# ######## sha256 ########hash = hashlib.sha256()hash.update(‘admin‘)print(hash.hexdigest())# ######## sha384 ########hash = hashlib.sha384()hash.update(‘admin‘)print(hash.hexdigest())# ######## sha512 ########hash = hashlib.sha512()hash.update(‘admin‘)print(hash.hexdigest())
Cryptographic algorithms and Hashlib modules