OpenSSL makes it easy to generate a pair of private keys and public keys, noting that the private key and public key are paired.
Private key: Refers to a string that only you know
Public key: Provides a string for everyone to know
There are two types of operations on private and public keys: 1. Public key encryption data, private key decryption data 2. Private key signature data, public key validation data
Let's analyze it one by one:
1. Public key encryption, private key decryption
A lot of friends want to send me messages, they send the message only want to give me a person to see, other people get this information is not to see. In order to satisfy this demand, we use public key encryption, private key decryption this way.
Friends sent me the information with everyone knows the public key to encrypt, and then sent to me, to decrypt the information must be the public key corresponding to the private key to decrypt the information, but only I know the private key, so friends sent over the message, only I can be solved by a person, but I can see only one person, Because other people do not have a private key, they cannot decrypt the information.
The illustrations are as follows:
2. Private key signature, public key authentication
Suppose I want to send a message to one of my friends, but there may be other people pretending to be me, and then sending messages to my friend, then my friend is not sure if the message sent to him or not I sent him, in order to meet this demand, use the private key signature, public key authentication.
I have to send the information, with only I know the private key to the signature, it is equivalent to the information on a my own unique tag, other people because there is no private key, so there is no such token, the message after the signature, sent to the friend, the friend know my private key corresponding to the public key, So to send his message with the public key to verify that the success of the verification, it means that this message I personally sent him.
The illustrations are as follows: