1. MD5 Encryption
MD5 encryption characteristics: irreversible operation (cannot be cracked, cannot be decrypted) The result of encrypting different data is a fixed-length 32-character string (no matter how large the file is, it remains the same).
The result of encrypting the same data is the same (that is, it is copied). Resistance to modification: the "fingerprint" of information. Any modification to the original data, even changing just one byte, will result in a significant difference in the obtained MD5 value.
Weak collision resistance: Given the original data and its MD5 value, it is very difficult to find another piece of data that has the same MD5 value (i.e., forged data).
Strong collision resistance: It is very difficult to find two different pieces of data that have the same MD5 value.
#coding=utf-8
"""
===========================
Author: 多测师_王sir
Time: 2020-07-06 15:54
Wechat: 15367499889
Company: 上海多测师信息有限公司
===========================
"""
import hashlib
def duoceshi_cn():
'''Encrypting the Duoceshi website www.duoceshi.cn'''
data = 'www.duoceshi.cn'
md5 = hashlib.md5() # Create MD5 encryption object
md5.update(data.encode('utf-8'))
sign = md5.hexdigest()
print('The encrypted text for the Duoceshi website www.duoceshi.cn is: {}'.format(sign))
def duoceshi_com():
'''Encrypting the Duoceshi website www.duoceshi.com'''
data = 'www.duoceshi.com'
md5 = hashlib.md5() # Create MD5 encryption object
md5.update(data.encode('utf-8'))
sign = md5.hexdigest()
print('The encrypted text for the Duoceshi website www.duoceshi.com is: {}'.format(sign))
if __name__ == '__main__':
duoceshi_cn()
duoceshi_com()
The results are as follows:
The encrypted text for the Duoceshi website www.duoceshi.cn is: 6288f286d86886810215373b0916e47e
The encrypted text for the Duoceshi website www.duoceshi.com is: 78c97debe231347bb7f7447c6ad8d1fa
2. Symmetric Encryption
Introduction:
Symmetric encryption algorithms are also known as traditional encryption algorithms.
The same key is used for both encryption and decryption.
Encryption and decryption process: plaintext -> key encryption -> ciphertext, ciphertext -> key decryption -> plaintext
Example:
Key: www.duoceshi.cn
Encryption algorithm: each character + www.duoceshi.cn
Plaintext: dcs
When the key is 1, the encryption result is: abmmx
When the key is 2, the encryption result is: dwddx
Advantages and disadvantages:
The algorithm is public, the computational load is small, the encryption speed is fast, and the encryption efficiency is high.
Both parties use the same key; security cannot be guaranteed.
There are three classic encryption algorithms:
1. DES (Data Encryption Standard): Data encryption standard (now used less frequently due to insufficient encryption strength, can be brute-forced).
2. 3DES: The principle is almost the same as DES, but it uses 3 keys to perform three encryptions on the same data, enhancing encryption strength. (Disadvantage: maintaining 3 keys greatly increases maintenance costs).
3. AES (Advanced Encryption Standard): Advanced encryption standard, currently used by the National Security Agency of the United States, and Apple’s Keychain access uses AES encryption. It is recognized as the safest encryption method and is the most popular algorithm in symmetric key encryption.
3. Asymmetric Encryption RSA
Introduction:
1. Asymmetric encryption algorithms are also known as modern encryption algorithms.
2. Asymmetric encryption is the cornerstone of computer communication security, ensuring that encrypted data cannot be cracked.
3. Asymmetric encryption algorithms require two keys: a public key (publickey) and a private key (privatekey).
4. The public key and private key are a pair.
Characteristics:
The encryption public key and private key are different; both are generated by the backend server and given to the frontend.
If data is encrypted with the public key, only the corresponding private key can decrypt it.
If data is encrypted with the private key, only the corresponding public key can decrypt it.
Algorithm strength is complex, and security relies on the algorithm and key.
Encryption and decryption speed is slow.
Comparison with symmetric encryption algorithms:
Symmetric encryption has only one key, which is not public; to decrypt, the other party must know the key.
Asymmetric encryption has two keys, one of which is public.
RSA and AES dual encryption: RSA encryption is complex and secure, but the performance of encryption and decryption is poor, suitable for encrypting small data. AES encryption is relatively simple, but the performance of encryption and decryption is strong, suitable for encrypting large data.
RSA application scenarios: Due to the much slower speed of RSA encryption and decryption compared to symmetric algorithms, in practical applications, it is usually adopted:
The encryption and decryption of the data itself use symmetric encryption algorithms (AES).
Use RSA algorithm to encrypt and transmit the keys needed for the symmetric algorithm.

E
N
D
