Analysis on the usage of Python md5 and sha1 encryption algorithms

  • 2020-06-12 09:50:14
  • OfStack

This paper introduces Python md5 and sha1 encryption algorithms. To share for your reference, specific as follows:

MD5

MD5, the full name of ES10en-ES11en Algorithm 5 (information-summary algorithm), was developed in the early 1990s by MIT Laboratory Computer Science and RSA Security Inc Ronald. It was developed by MD2, MD3 and MD4. Is an irreversible encryption algorithm, is currently the most reliable encryption algorithm 1, has not been able to reverse the operation of the program has been developed, it can correspond to any string can be encrypted into 1 only 1 fixed length code.

Features:

First of all, it's irreversible, there's no systematic way to know what the original MD5 code was

Secondly, this code is highly discrete and has no rules to follow. Even if a small change in the original message causes a huge change in MD5, the resulting MD5 code is unpredictable.

Finally, because the code is 128 bits long, the probability of having the same MD5 code between any pieces of information is extremely low and is generally considered impossible.

USES:

It is generally believed that MD5 code can only represent the characteristics of the original information, which is usually used for cryptographic storage of passwords, digital signature, file integrity verification, etc

SHA1

The full name of SHA1 is Secure Hash Algorithm(secure hashing algorithm), which is designed by NIST NSA to be used since DSA1. It produces a hash value of 160bit for the input with length less than 264, so it has better anti-exhaust (ES58en-ES59en). SHA-1 is designed based on the same principle as MD4 and mimics the algorithm. SHA-1 is a national standard issued by the United States Bureau of Standards and Technology (NIST). It is one of the most widely used hash function algorithms and the most advanced encryption technology at present. It is used by government departments and private owners to process sensitive information. SHA-1 is based on MD5 and MD5 is based on MD4.

SHA-1 has 32 more ciphertext than MD5, so it is more secure. For the same reason, MD5 is faster than ES74en-1.

Examples of usage:

hashlib module in Python is a library specially providing hash algorithm. Now it includes md5, sha1, sha224, sha256, sha384, sha512. It is very simple and convenient to use. Usage:


import hashlib
hash_new = hashlib.sha1() # or hashlib.md5()
with open('driver.xml.tar.bz2','rb') as fp: # Open the file, 1 Must to 2 Hexadecimal open 
  while True:
    data = fp.read() # Read file block 
    if not data: # Until you read the document 
      break
    hash_new.update(data)
hash_value = hash_new.hexdigest() # generate 40 position (sha1) or 32 position (md5) the 106 Base string 
print hash_value

PS: For those who are interested in encryption and decryption, please refer to our online tools:

Text online encryption and decryption tools (including AES, DES, RC4, etc.) :
http://tools.ofstack.com/password/txt_encode

MD5 Online encryption tools:
http://tools.ofstack.com/password/CreateMD5Password

Online hashing/hashing algorithm encryption tools:
http://tools.ofstack.com/password/hash_encrypt

Online MD5/hash/SHA-1/SHA-2/SHA-256/SHA-512/SHA-3/RIPEMD-160 Encryption tool:
http://tools.ofstack.com/password/hash_md5_sha

Online sha1 sha224 / sha256 sha384 / sha512 encryption tools:
http://tools.ofstack.com/password/sha_encode

For more information about Python, please refer to: Python Encryption and Decryption Algorithms and Techniques summary, Python Coding techniques Summary, Python Data Structure and Algorithm Tutorial, Python Function Using Techniques Summary, Python String Manipulation Techniques Summary and Python Introduction and Advanced Classic Tutorial

I hope this article has been helpful in Python programming.


Related articles: