Publish: 2019-11-17 | Modify: 2019-11-17
With the rapid development of the Internet, network security has been increasingly valued. The traditional HTTP protocol transmits data in plain text, which poses a great security risk if the HTTP request is intercepted by hackers and the content is easily obtained. In order to solve this problem, Netscape developed the HTTPS protocol, which encrypts data transmission. Even if a hacker intercepts the data during transmission, it cannot be deciphered, ensuring the security of network communication.
Before understanding the HTTPS protocol, we first need to know some basics of cryptography.
Symmetric encryption, also known as private key encryption, is when the sender and receiver of information use the same key to encrypt and decrypt data. Symmetric encryption is characterized by its publicly available algorithm, fast encryption and decryption speed, and suitability for encrypting large amounts of data. Common symmetric encryption algorithms include DES, 3DES, TDEA, Blowfish, RC5, and IDEA.
To put it simply, imagine there is a box with two identical keys, key A and key B. Key A puts a treasure map into the box and sends it to B through a courier. Without the key, no one knows what's inside the box. When B receives the box, they can use their key to open it and find the treasure map. This is symmetric encryption.
Asymmetric encryption, also known as public key encryption, provides better security compared to symmetric encryption. In symmetric encryption, both communication parties use the same key. If one party's key is compromised, the entire communication can be decrypted. Asymmetric encryption uses a pair of keys, namely the public key and private key, which always appear together. The private key is kept by the owner and must not be disclosed. The public key is publicly available to anyone. Encryption can be done with either the public key or the private key, and decryption can be done with the other key.
Encryption with the public key can only be decrypted with the private key: Plain text + Encryption algorithm + Public key => Cipher text, Cipher text + Decryption algorithm + Private key => Plain text
Encryption with the private key can only be decrypted with the public key: Plain text + Encryption algorithm + Private key => Cipher text, Cipher text + Decryption algorithm + Public key => Plain text
As encryption and decryption use two different keys, this is why it's called asymmetric encryption. The main algorithms used in asymmetric encryption are RSA, Elgamal, Rabin, D-H, and ECC (Elliptic Curve Cryptography).
HTTPS protocol = HTTP protocol + SSL/TLS protocol. During HTTPS data transmission, SSL/TLS is used to encrypt and decrypt data, while HTTP is used to transmit the encrypted data. Therefore, HTTPS is a combination of HTTP and SSL/TLS.
To ensure both security and efficiency, HTTPS uses both symmetric and asymmetric encryption. Before transmitting content, it uses asymmetric encryption to exchange public keys and client keys (this data is very small). When it comes to transmitting the actual content, it uses the client key for symmetric encryption (considering transmission efficiency).
An HTTPS request actually consists of two HTTP transmissions, which can be divided into 8 steps:
The entire process is illustrated in the following diagram:
Some parts of this article are referenced from:
I come from China and I am a freelancer. I specialize in Linux operations, PHP, Golang, and front-end development. I have developed open-source projects such as Zdir, ImgURL, CCAA, and OneNav.