Talk about the encrypted transmission process of HTTPS

1 Summary

(1) Symmetric encryption
Both parties in communication use the same key for encryption and decryption.

(2) Asymmetric encryption The
two parties in communication use different keys for encryption and decryption, that is, each party has a pair of its own public key and secret key. Suppose two users want to encrypt and exchange data, and the two parties exchange public keys. When using, one party uses the other party's public key to encrypt, and the other party can decrypt it with its own private key.

2 HTTPS encryption process

HTTPS actually means that the HTTP protocol communicates with SSL first, and then communicates with SSL (port 443) and TCP, which is equivalent to putting a layer of armor on HTTP.
Insert picture description here
Specific process:

① Certificate verification stage:
1) The browser initiates an HTTPS request;
2) The server returns an HTTPS certificate (including the public key of the server);
3) The client verifies whether the certificate is valid, and if not, a warning will be prompted.

② Data transmission stage:
1) When the certificate is verified to be valid, a random number is generated locally;
2) The random number is encrypted by the public key, and the encrypted random number is transmitted to the server;
3) The server uses the private key to pair the random number Decryption;
4) The server constructs a symmetric encryption algorithm through the random number passed in by the client, encrypts the returned result content and transmits it.

Insert picture description here
The encryption and decryption efficiency of asymmetric encryption is very low, and in the application scenario of http, there is usually a large amount of interaction between the end and the end (each transmission needs to pass the public key of both parties), and the efficiency of asymmetric encryption is unacceptable of.

In order to improve communication efficiency and ensure a certain degree of security, HTTPS uses asymmetric encryption in the key exchange process, and uses symmetric encryption in the subsequent stage of establishing communication exchange messages. The specific method is: the party sending the ciphertext uses the other party's public key to encrypt the "symmetric key" (random number), and then the other party uses its own private key to decrypt and get the "symmetric key" (random number), so On the premise of ensuring the security of the exchanged keys, symmetric encryption can be used for communication. Therefore, HTTPS uses a hybrid encryption mechanism that uses both symmetric encryption and asymmetric encryption.

Guess you like

Origin blog.csdn.net/glpghz/article/details/108316215