Current location - Quotes Website - Signature design - Symmetric encryption, asymmetric encryption, digest, digital signature, digital certificate
Symmetric encryption, asymmetric encryption, digest, digital signature, digital certificate

As a developer, I have heard the concepts of symmetric encryption, asymmetric encryption, digest, digital signature and digital certificate, which are used to ensure the security of data transmission in the process of Internet communication. Some people may wonder, if I encrypt the transmitted data, it will be safe. Why do I have to make so many tricks? This paper mainly explains the practical functions of these concepts through a case.

before that, let me briefly introduce these concepts.

symmetric encryption means that the same secret key is used for encryption and decryption. Its characteristic is high encryption speed, but the secret key is easy to be intercepted by hackers, so the security is not high. Common algorithms are AES and DES.

asymmetric encryption means that different keys are used for encryption and decryption. They appear in pairs, called public keys and private keys. Knowing one of the keys can't deduce the other. Content encrypted with public key needs to be decrypted with private key, and content encrypted with private key needs to be decrypted with public key. Asymmetric encryption is characterized by high security, but the disadvantage is that the encryption speed is slow. RSA algorithm is common.

The so-called digest is a string of characters obtained by a piece of information or a file through a hash algorithm (also called digest algorithm). The characteristic of the algorithm is that the abstracts calculated by different files are different (it may be the same, but the possibility is very, very low). For example, even if only one byte of a 1G video file is changed, the final calculated abstracts are completely different, so the summarization algorithm is usually used to judge whether the file has been tampered with. Another feature is that it is impossible to deduce the information of the source file through the abstract. Commonly used summarization algorithms are MD5, SHA, etc.

a digital signature is the encrypted information of the abstract of a file. The digital signature is sent to the receiver together with the source file. After receiving it, the receiver calculates a summary of the file with a summary algorithm, and then compares it with the summary in the digital signature. If the two are inconsistent, the file has been tampered with.

a digital certificate is a file generated by a certificate authority, which generally contains information such as public key, name of public key owner, digital signature of CA, expiration date, name of the authority, serial number of certificate, etc. Among them, the digital signature of CA is the key to verify whether the certificate has been tampered with. In fact, it is to abstract the contents in the certificate except the digital signature of CA to get a summary, and then the CA institution encrypts this summary with its own private key to generate the digital signature of CA, and the CA institution will disclose its public key, which is used to decrypt the digital signature of CA when verifying the certificate, and then to verify whether the certificate has been tampered with.

Scene:

Zhang San wants to find someone to decorate a house. The principle is to decorate the house for whoever offers the lowest price, so the quotation document is confidential. Let's take a look at the risks of transmitting quotation documents in different ways.

Now Li Si wants to take on this decoration job. He has made a quotation document (file name: lisi.txt, file content: quotation 5, yuan). Li Si then encrypts this file with a symmetric key 123. Finally, Li Si sent this secret key and the encrypted file to Zhang San. After Zhang San received it, he decrypted it with this secret key and learned that Li Si's offer was 5, yuan.

At the same time, Wang Wu also wants to take the decoration job. He originally wanted to offer 55, yuan, but he was afraid that the offer would be too high and lost the job. It happened that Wang Wu was a master hacker, so he intercepted the secret key and encrypted file that Li Si sent to Zhang San, and learned that Li Si's quotation was 5,. Finally, Wang Wu changed his quotation to 49, yuan and sent it to Zhang San. As a result, Wang Wu accepted the decoration work.

Conclusion:

If symmetric encryption is used, once the secret key is intercepted by a hacker, the encryption will be useless, so the security is relatively low.

firstly, Zhang San will generate a pair of secret keys, the private key is zhangsan1, and the public key is zhangsan2. Zhang San will save the private key himself and publish the public key.

Li Si encrypts the quotation file list.txt with Zhang San's public key zhangsan2 and transmits it to Zhang San, and then Zhang San decrypts it with Zhang San's private key zhangsan1 to get that Li Si's quotation is 5, yuan.

At this time, even if Wang Wu intercepts the quotation file sent by Li Si to Zhang San, Wang Wu can't decrypt the file because he doesn't have Zhang San's private key, so he can't know the quotation of Li Si. In the end, Wang Wu lost the opportunity of decoration because of the offer of 55, yuan.

therefore, asymmetric encryption can ensure the security of data transmission. But here is a digression. Since asymmetric encryption has high security, why not eliminate symmetric encryption? In fact, the key lies in the encryption speed. Asymmetric encryption has a large amount of calculation, so the encryption speed is very slow. If messages are sent very frequently, using asymmetric encryption will have a great impact on performance. Therefore, in the actual development process, symmetric encryption and asymmetric encryption are usually combined. That is, the symmetric encryption key is sent after asymmetric encryption, which can ensure that the symmetric encryption key is not intercepted by hackers, and then symmetric encryption is used when sending business data. This ensures both security and encryption speed.

Conclusion:

Asymmetric encryption can prevent hackers from intercepting encrypted content, which is highly secure.

We all said that asymmetric encryption is safe, so why do we need digital signature?

imagine that Wang Wu intercepted Li Si's quotation document. Although Wang Wu can't know Li Si's actual quotation, he can completely forge a copy of Li Si's quotation (file name: lisi.txt, file content: quotation 6,), and then encrypt this forged document with Zhang San's public key zhangsan2 to replace the original quotation document. After Zhang San received it, she found that the quotation was 6,, so Zhang San thought that the quotation of Li Si was 6,, and finally decided to give the decoration work to Wang Wu who quoted 55,.

The key to this problem is that Zhang San can't know whether the quotation file has been tampered with. To solve this problem, digital signature is needed.

First of all, Li Si needs to generate a pair of asymmetric encryption keys, the private key lisi1 is saved by himself, and the public key lisi2 is sent to Zhang San. Then Li Si gets a digest of his quotation file through the digest algorithm (assuming that the digest is aaa), encrypts the digest with his private key lisi1 to get the digital signature of the quotation file, and finally sends the encrypted quotation file and the digital signature to Zhang San. After Zhang San receives it, he decrypts the digital signature with the public key lisi2 sent by Li Si to get the abstract aaa. Then decrypt the encrypted file with its own private key zhangsan1 to get the quotation source file, and then summarize the quotation source file to see if the calculated result is aaa, if not, it means that the quotation file has been tampered with.

In this case, if Wang Wu intercepts the document sent by Li Si to Zhang San. Wang Wu can't decrypt the quotation documents. If Wang Wu forges a quotation document, when Zhang San receives it, he will find that the quotation document does not match the digital signature. Can Wang Wu forge the quotation document and the signature at the same time? Because Wang Wu doesn't have Li Si's private key, he can't encrypt the abstract of the forged quotation document, so he can't forge the signature.

Conclusion:

Although asymmetric encryption can ensure that the contents of encrypted files are not stolen, it cannot guarantee that files are not tampered with. Digital signature is used to verify whether the file has been tampered with.

since asymmetric encryption can ensure the security of file contents and digital signature can ensure that files are not tampered with, what's the use of digital certificates?

let's imagine that Wang Wu himself has generated a pair of secret keys for asymmetric encryption. The private key is wangwu1 and the public key is wangwu2. Wang Wu intercepted Li Si's public key lisi2 when he sent it to Zhang San. Wang Wu replaced Li Si's public key lisi2 with his public key wangwu2, so Zhang San finally received the public key from Wang Wu, but Zhang San didn't know about it. Later, Li Sifa's digital signature and encrypted quotation file were intercepted by Wang Wu, and Wang Wu forged a quotation file. At the same time, he encrypted the abstract of the quotation file with his private key to generate a forged signature and sent it to Zhang San. After Zhang San received it, he verified that the digital signature and the quotation file matched, and thought that the quotation file was true.

The key to this problem is that Zhang San can't confirm whether the received public key is sent by Li Si or not, and then the digital certificate comes into play. Li Si applies for a digital certificate from an authoritative digital certificate authority. The certificate contains the public key (lisi2) and the owner of the public key (Li Si), and then Li Si sends the certificate to Zhang San. Zhang San can know whether the public key is Li Si's or not through the information in the certificate.

Is it possible that the certificate was intercepted and tampered with by Wang Wu during the sending process? You should know that the certificate also contains the digital signature of CA. This signature is that the certificate authority encrypts the abstract of the certificate with their own private key, and the public key is public. Therefore, even if Wang Wu intercepts and falsifies the contents of the certificate, he can't forge the signature of the certificate authority. After receiving the certificate, Zhang San will find that the certificate has been tampered with by verifying the signature. So this step can guarantee the real security of data transmission.