| Plain text |-> Public key encryption->; | Ciphertext |-> Private key decryption->; Plain text |
This encrypted path is used for encrypted communication with others, which is equivalent to symmetric encryption.
Let's go back to the example of Alice and Bob.
If Bob wants to use asymmetric encryption algorithm to receive information sent by other people's private messages, the steps are as follows.
1. First, Bob needs to use a specific convention algorithm (such as RSA) to generate a key and a public key. The key is kept by oneself, and the public key is public.
2. After Alice gets Bob's public key, she can send the message "Alice has transferred 1BTC to Bob, please check it." Encryption.
3. Alice then sends the ciphertext (for example, "FH39ggJ+shi3djifg35") to Bob.
4. After receiving the message, Bob decrypts it with his private key and restores the original message "Alice has transferred 1BTC to Bob, please check it."
Because the message encrypted with Bob's public key can only be decrypted with Bob's private key (Bob's public key is not good either), and the private key is only owned by Bob, so even if the message is hijacked by a third party, he can't restore the message plaintext.
Application 2: Digital Signature
On the other hand, what if you encrypt it with the private key first? This gave birth to another important application of asymmetric encryption: digital signature.
Let's go back to the example of Alice and Bob.
In the bitcoin system, it is similar to "Alice has transferred 1BTC to Bob, please check it." Such news will eventually be recorded in the books by miners, which is related to the interests of both sides. The beneficiary of this information is Bob. Let's think about it. What if Bob has been broadcasting the news that Alice transferred money to him online?
Bob: "Alice has transferred 1BTC to Bob"
Bob: "Alice handed over 2BTC to Bob."
Bob: "Alice handed over 3BTC to Bob."
…
So we need a mechanism to prove that Alice is "voluntary", that is, Alice sent the message herself. The steps are as follows:
1.Alice needs to use a specific convention algorithm (such as RSA) to generate keys and public keys. The key is kept by herself, and the public key is public.
2. When Alice wanted to send a message, Alice had already forwarded 1BTC to Bob, please check it. | My public key is: "gh3giPGFN2jgh3sF". Alice encrypts information with her private key. Assuming that the encrypted ciphertext is SHG356g3T4+dh4fh, this ciphertext can now be regarded as Alice's digital signature.
3.Alice puts the message plaintext and digital signature together and sends them to the network.
The message sent is similar to this. Alice has transferred 1BTC to Bob. Please check it. | My public key is: "gh3giPGFN2jgh3sF". | Signature: "SHG356g3T4+dh4fh"
4. After receiving the message, everyone in the network can do the following to complete the verification:
Please check the message that Alice has transferred 1BTC to Bob. | My public key is: "gh3giPGFN2jgh3sF". | Signature: "SHG356g3T4+dh4fh"
The digital signature SHG356g3T4+dh4fh signed with the private key is decrypted with the public key gh3giPGFN2jgh3sF provided by Alice in the message.
Please check whether Alice has transferred 1BTC to Bob. | My public key is: "gh3giPGFN2jgh3sF" for comparison.
If they are consistent, it means that Alice sent the message herself, because only Alice has Alice's key.
If not, it means that the message was not sent by Alice, or that the message was sent by Alice but was tampered with by others.
5. Then, through the method described in 4, Bob confirms that Alice gave him the transfer of 1BTC.
Other people in the network (miners) have successfully verified the truth of this message, testifying for Bob that his account has increased by 1 BTC, while Alice's account has decreased by 1 BTC.