In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "what is the difference between symmetric encryption and asymmetric encryption". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn the difference between symmetric encryption and asymmetric encryption.
I. Preface
Before we understand the principle of encryption, let's take a look at such a story.
Xiao Hong and Xiao Ming are lovers. One day, Xiao Hong sent a text message to Xiao Ming and said, "Honey, there is no money on my bank card. Please transfer 10,000 yuan to me." Anyone who has been deceived knows that it may be a thief who stole Xiao Hong's handbag and sent a text message with his cell phone. But we Xiaoming learned the principle of encryption, so he replied: "you can just swipe my bank card, the password plus the date of our first date is 663156." Obviously, only Xiao Ming and Xiao Hong know when their first date is. Assuming it is April 1, 2008, Xiao Hong can get the bank card password according to the calculation of 663156-200841-462315, and then she can spend.
This is the essence of encryption, adding the information and the key to get the encrypted information. Only people who know the key can decrypt it.
What is the secret key
Since encryption requires a key, what is the key?
A key is a string of passwords acting on encryption, which encrypts, transmits and reaches the receiver and listener through the key. Because the receiver also has a key, the receiver can decrypt it according to the key. So as to prevent the disclosure of communication information.
What is symmetric encryption
The preface tells a story of symmetrical encryption. Both Xiao Ming and Xiao Hong know the date of their first date. Therefore, the traditional symmetric encryption requires both sides of the communication to keep the same key, which is used for encryption and decryption. So asymmetric encryption is also called single key encryption.
The advantage of symmetric encryption is that the encryption and decryption speed is fast, but the security is low. Once the key is leaked, all the encrypted information will be cracked. At the same time, the transmission and secrecy of the key has become a difficult problem. In order to solve the problem of key transmission, there is a technology to establish a shared key through key exchange. How to establish a shared key exactly? Let's look down.
3.1 create a shared key
In the trio world of Xiao Ming, Xiao Hong and the thief, because Xiao Ming has learned the principle of encryption and knows Diffy-Herman key Exchange (Diffie-Hellman Key Exchange), he knows how to establish a shared key.
3.1.1 pigment mixing trick:
Let's take a look at how to create a shared key through a paint mixing trick.
Suppose there are Xiaoming, Xiao Hong and thief in the room, each of whom has the same color paint. There are also these paints in the middle of the room. Next, Xiaoming is going to establish a shared key with Xiao Hong. At this point, Xiaoming said to everyone, "I want to use blue." Then Xiao Ming chose yellow from his own paint, this yellow is Xiao Ming's private key, Xiao Hong and the thief do not know. Xiaoming mixes his private key yellow with public key blue and gets a color that can't be decomposed. Let's call it "Xiaoming-blue" (although we all know that yellow + blue turns green, but here we want to know whose mixed color it is. Or by name plus public key color), and then Xiaoming announced "Xiaoming-blue". Similarly, after Xiao Hong heard that Xiao Ming said to use blue, she also chose her own private key red and public key blue to mix, got the "little red-blue" and published it.
At this time, the room Xiaoming, Xiao Hong, thief three people all know a few information.
1. They all used blue.
two。 Xiao Ming announced "Xiao Ming-Blue" (Xiao Hong and the thief do not know what kind of pigment is mixed with blue)
3. Xiao Hong announced "Little Red-Blue" (Xiao Hong and the thief do not know what kind of pigment is mixed with blue)
Then, when it was time to witness the miracle, Xiaoming mixed "Little Red-Blue" with his private key "Yellow" and got the new paint of "Little Red-Blue-Xiaoming". Similarly, Xiao Hong gets "Xiao Ming-blue" mixed with her private key "red" to get "Xiao Ming-blue-Xiao Hong". Did you find out? "Xiao Hong-Blue-Xiao Ming" and "Xiao Ming-Blue-Xiao Hong" are exactly the same color. The thief did not know the color of Xiao Ming's and Xiao Hong's private keys and could not mix them with the same color.
At this point, the shared key is established. After understanding the establishment process of the shared key, we will bid farewell to the physical paint and establish the shared key digitally.
Note: you may have thought that thieves can mix their own paint with the public key "blue" and try to get "Xiaoming-blue" and "little red-blue". This method is called exhaustive method, that is, trying all the possibilities to crack the information, so encryption algorithms can be cracked by exhaustive method in theory, but in practice, supercomputers need trillions of years to come up with all the possibilities.
3.1.2 multiplication trick:
First, let's assume that multiplication, like pigment mixing, is indecomposable, and see how multiplication can be used to establish a shared key with numbers.
Xiao Ming made public a number 5, and then Xiao Ming chose a private number 4, and then mixed the two by multiplication to get "Xiao Ming-5" (20), and then Xiao Hong also chose a private number 7 to get "Xiao Hong-5" (35). Xiao Ming got 35, 4, 140 and Hong, 20, 7, 140. The shared key establishment is complete.
As we all found out, after the thief knows the three numbers 20, 35, 5 and 5, he can calculate the private keys of Xiao Ming and Xiao Hong by division. So, next we will see how to use multiplication tricks in practice to prevent the private key from being calculated.
3.2 Diffy-Herman key exchange algorithm
We all know the power operation, but it is more difficult for the computer to calculate. Therefore, we will use exponentiation as a multiplication trick to establish a shared key. At the same time, we also need to understand the principle of clock calculation, the clock here can be understood as the clock we often see, our common clock is 12, if the current is 10:00, after 4 hours, it will become 2 p.m. That is, (10-4) mod12=2. After understanding clock calculation and exponentiation, let's get down to business.
Or Xiao Ming, Xiao Hong and the thief's room, Xiao Ming declared that the clock is 11, the bottom of the exponentiation is 2, and then Xiao Ming and Xiao Hong chose their own private keys 4 and 7 respectively.
The first step is for Xiao Ming to mix his own "Xiao Ming-11jue 2" and Xiao Hong to get his own "Xiao Hong-11jue 2".
In the second step, Xiao Ming gets "Xiao Hong-11jue 2" (7) for calculation, and Xiao Hong gets "Xiao Ming-11jue 2" (5) for calculation.
Have you noticed that Xiao Ming and Xiao Hong established a shared key 3, while the thief could not calculate the key or Xiao Hong's private key according to the known numbers 11, 2, 5, 7. With the shared secret key, Xiao Ming and Xiao Hong can securely carry out encrypted transmission.
3.3 AES symmetric encryption proc
AES, whose full name is Advanced Encryption Standard, is the most popular symmetric encryption algorithm with fast encryption and decryption speed. AES supports keys with lengths of 128,192,256 bits. The longer the key, the higher the security. In AES encryption, plaintext is divided into many small pieces of plaintext, then each piece of plaintext is encrypted separately, and the encrypted ciphertext is transmitted, and then the receiver decrypts the ciphertext into blocks to get plaintext.
As shown in the following figure:
Xiaoming and Xiao Hong have negotiated the key 3 in the previous step. It is then possible to communicate through symmetric encryption.
In the room of Xiao Ming, Xiao Hong and the thief, Xiao Ming wanted to tell Xiao Hong the password "462315", so:
The first step: split the password according to the length of one bit (usually 128 bits in practice); it becomes "4", "6", "2", "3", "1" and "5".
Step 2: encrypt each plaintext with key 3, and the result is "795648". Then Xiao Ming tells Xiao Hong and the thief, "my password is 795648."
The third step: after Xiao Hong got the ciphertext, she cut the ciphertext into blocks and decrypted each block through key 3 to get the correct password "462315", while the thief could not decrypt the correct information because he did not know the key.
IV. What is asymmetric encryption
In symmetric encryption, encryption and decryption use the same key. Therefore, in asymmetric encryption, encryption and decryption use different keys. Keys in asymmetric encryption are divided into public keys and private keys. As the name implies, the public key is public, and anyone can encrypt the information through the public key, but only the person with the user's private key can decrypt the information. Asymmetric encryption brings the benefit of avoiding the pain of transmitting and saving the same key in symmetric encryption.
Now the most popular asymmetric encryption algorithm is the RSA encryption algorithm, exactly how to do it, let's move on.
4.1 RSA encryption proc
Wikipedia explains that the RSA encryption algorithm is an asymmetric encryption algorithm that is widely used in public key encryption and e-commerce. RSA was proposed by Ron Rivest, Adi Shamir and Leonard Adleman in 1977. All three of them worked at MIT at the time. RSA is made up of the initials of the three surnames.
Earlier, we talked about how to establish an irreversible shared key through clock calculation and power function (a computer can calculate a private key by exhaustive method, but even a supercomputer has to calculate a shared key for trillions of years in the actual scenario). Because Xiao Hong is Xiao Ming's girlfriend, Xiao Ming tells her the principle of RSA encryption algorithm in front of Xiao Hong every day, so Xiao Hong also knows how to get her own public key and private key. Next, let's follow in Xiao Hong's footsteps to see how the public and private keys encrypted by RSA are calculated.
The first step: Xiao Hong chooses two large prime numbers p and Q. Here, in order to facilitate calculation, choose 2 and 11.
Step 2: calculate the product n=p*q=2*11=22 of p and Q
The third part: calculate the Euler function φ (n) = (pmur1) * (qmer1) = 10 of n.
Step 4: select an integer e, which is less than φ (n) and prime with φ (n), {1meme3, 7, 9}, and choose eBay 7 here.
Step 5: calculate the modular inverse element (ed mode φ (n) = 1) of e for φ (n).
At this point, Xiao Hong gets her own public key (NMague e) and private key (NMague d). Where n is the size of the clock, e and d are the powers of the power function. Then encrypt and decrypt the data through the calculated public key and private key.
Or Xiao Ming, Xiao Hong and the thief three people, Xiao Hong said to everyone, my public key is (22 Magi 7), Xiao Ming knew Xiao Hong's public key, want to tell Xiao Hong about his message "14" to Xiao Hong, so he used Xiao Hong's public key for encryption.
The specific steps are as follows:
The first step: Xiao Ming calculates according to the message 14 to be encrypted, gets the encrypted message 20, and then tells the 20 to Xiao Hong and the thief
Step 2: Xiao Hong has her own private key, decrypts the encrypted message 20, and gets the message that Xiao Ming wants to pass to Xiao Hong. As for the thief, he knows 22pi 7pm 20, but he doesn't know Xiao Hong's key (22p3), so he can't decrypt the correct information.
RSA encryption algorithm also plays a huge role in digital signatures, assuming that the thief can pretend to be Xiao Hong, saying that Xiao Hong's public key is (22), while Xiao Ming does not know that it is pretending to be a thief. After encrypting according to the thief's public key, the result is decrypted by the thief. The function of digital signature is to prevent information from being tampered with. When Xiao Hong says that her public key is (22), she uses the private key to add a signature to this message (usually using MD5 value to calculate the signature), and Xiao Ming gets the public key (22) and signature 13. Xiao Ming uses the public key to calculate whether the information has been tampered with after getting the signature.
Fifth, the practical function of encryption
In this paper, a very small number is used to explain the encryption principle, so that the reader can easily carry out the calculation. In practical use, the number of n is very large, in which the length of n is more than 768, and the length of 1024 is considered to be basically safe.
(123018668453011775549495838496277753569533479219732259389956474942774063845925195732634531548487917026229134616704291431602221240479274779806653519945598569023413604444484821290898817704749371368568968890817704749381368568968968938838738768968968968938838738768968968968938838938768968968938912433388288387787628711632531733836836436736799424274747292437377980665351994599856902143413784416484821290890817704749371366856896896896896896886896896886896896896886896896896896896896896896896891243333388283387387876228147116325329336460736736729274747794027473779406653519945998569021434137844169848212908908177047494937136685685689689689668968912433388288288387876228711632532932931602221240479274779406653779806653519945998565690234136044169848212908688177047498371366856896689912433383882883878762287116325327399489 × 3643673672927474779402747377940665 Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.