1. Introduction

This article mainly shares the encryption method that THE author has used or understood in the past.

“Understand” rather than “familiar with”, more appropriate to express the difficulty level of the article, the underlying principle of the author is also confused, not to mention what encryption algorithm used.

This paper can only talk about the different encryption, basic introduction, encryption characteristics, application scenarios.

Welcome to point out any misunderstanding.

Examples will be given in githug later, I believe there are many online demos. If can't find, can leave a message I provide.Copy the code

2. What is encryption

First of all, encryption is about not exposing our original information, encrypting the clear text into ciphertext and sending it over the communication path. Eavesdroppers cannot read or understand the text. The ciphertext is decrypted into plaintext at the receiving end.

Encryption makes the program more secure.

3. Encryption mode

Before we summarize the encryption methods, let’s generalize them.

Symmetric encryption is the use of a single key to encrypt and decrypt data. Its advantage is speed. Because of its speed, symmetric encryption is often used when the sender of a message needs to encrypt a large amount of data.

Its advantages are open algorithm, small amount of calculation, fast encryption speed, high encryption efficiency.

One drawback is that both sender and recipient must use the same key. You must share the key with the recipient.

Asymmetric encryption is a kind of improvement against the defects of symmetric encryption. Asymmetric encryption algorithm is a secret key method.

He needs two keys, public and private. If the public key is used to encrypt data, only the corresponding private key can be used to decrypt the data. If the private key is used to encrypt data, only the corresponding public key can be used to decrypt the data. This is asymmetric encryption.

It’s more secure than symmetric encryption, but not as efficient as symmetric encryption.

4. Encryption method

MD5

Let’s start with MD5.

MD5 is not symmetric or asymmetric, and it is not even an encryption algorithm. In principle it is irreversible. You’re allowed to encrypt, not decrypt.

So you might wonder, why can’t you decrypt it? It has a wide range of applications.

scenario

Our system requires the code “Open Sesame” for access. You can’t just fill in “Open Sesame,” or tell someone the code word is “Open Sesame.” That way people will know your code.

So what to do? This time you can use our “Open Sesame” MD5 encryption. Encrypted, it could be something sdadgjsdgJsdagJsdGGdjsag. At this time, the guard only needs to compare you and check whether your encrypted values are the same to give you permission. The portal itself does not know what the “code” is.

The characteristics of

What are the features of MD5 encryption?

  • Compressibility: The length of the CALCULATED MD5 value is fixed for any length of data.

  • Easy to calculate: It is easy to calculate the MD5 value from the raw data.

  • Modifiability: Any change to the original data, even if it is only 1 byte, will result in a significant difference in the MD5 value.

  • Strong collision resistance: Given the original data and its MD5 value, it is very difficult to find a data with the same MD5 value (i.e. forged data).

other

In principle it is irreversible. But a lot of times, you don’t follow the rules. There are numerous websites about MD5 decryption on the Internet. We still can’t take him as the only standard. We can encrypt several times as much as possible.

DES

DES is a symmetric encryption algorithm, but it has been used less and less in recent years because DES uses a 56-bit key that can now be restored at any time.

Basic to AES replacement, but this article is simply mentioned.

AES is more secure, efficient, and flexible than DES. Therefore, AES is preferred for symmetric encryption.

AES

Also known as “advanced Encryption Standard”, it later replaced DES.

We can use the AES tool to generate a key (available at: tool.chacuo.net/cryptaes). then

Aes is still relatively high efficiency, can be said to be the most popular symmetric encryption.

scenario

Packets not suitable for plaintext transmission are transmitted between programs

The characteristics of
  • Fast encryption speed
  • Suitable for large amounts of data
  • Data can be restored after processing

RSA

RSA is a masterpiece of asymmetric encryption algorithms.

The security of RSA depends on the decomposition of large numbers. N less than 1024 bits has been proved to be insecure. In addition, because the RSA algorithm performs large number calculation, the fastest RSA algorithm is times slower than DES, which is the biggest defect of RSA. But RSA is still a high-powered algorithm. One way to think about RSA is that, according to number theory, it is relatively easy to find two large prime numbers, but extremely difficult to factor their product, so the product can be exposed as an encryption key.

It is important to note that RSA has a length limit, so if the data is likely to be too long, you should encrypt it in segments in advance

The characteristics of

Advantages:

  • Secure. Secret keys are not exposed. Public keys are safe

Disadvantages:

  • The key size is large, and is generally used to encrypt a small amount of data, such as the DES key.
  • The encryption and decryption speed is slow
  • Implement segmented encryption
  • The encrypted data is large
scenario

Rsa can be used when sending important data to a customer to prevent interception and modification of the data.