Public Key vs Private Key in Cryptography
Previously we talked about End to End Encryption, this time we will talk about Public Key vs Private Key in Cryptography. Before we start discussing their difference. We need to understand what they are and how they are used. Public and Private keys are the pair of two keys that are related to each other. These keys have a special purpose to serve, If you encrypt a packet of data with one key, that encrypted data packet can be decrypted with the other key of this pair.
We use the Public key to encrypt and decrypt the data packets. The public key is to share publically. We can share it with a group of people or a special person. When you share the public key with a person or a group of people, It means you are allowing them to send you data packets secretly.
The public key is the other key of the pair. We don’t share Private key with anyone. As we discussed earlier, we can also use a Private key to encrypt and decrypt the data packets. How we use them to communicate with others securely is the point to understand, so let’s understand.
How to Use Public and Private Keys to Communicate Securely
Suppose you want to send me a file. You want to make sure that I am the only person who opens it. You do not want the hacker to hack into the communication channel and steal your file and then read it.
In order to communicate secretly, we both need to generate a pair of public-private keys. You can use Putty to generate the keys. We will share the public keys over the internet. We don’t need to worry if a hacker steals the public key. If a hacker somehow manages to steal the public key, it is useless for him. I know you are wondering how you will understand it by the end of this article.
Now you have my public key and I have yours. You want to send me a file secretly. You need to make use of my public key and encrypt that file.
After encryption, the file becomes unreadable. The only key that can decrypt this file and make it readable is my private key.
You can send this file to me, the file is completely safe because it is encrypted. Once I receive the file, I will use my private key and decrypt it. This is how you can send me a file in a secure way and forget about someone stealing it.
Why Do We Have Two Keys
We have two keys because anything that we share over the internet cannot be taken for granted for its security. If we will have only one key for encryption and decryption then, we will have to share the same key with the other person over the internet.
This is why we have two keys, one key is to share and another key is to keep a secret. Locking with one key, unlock it with the other key. This is such a clever idea.
How to Make Sure the Received File is from the Right Person
Those who have gone through this article with their best concentration will ask one question. That question is as follows –
How do we know the file we have received is from the right person. My public key is available publically and anybody can send me a file pretending to be someone else.
For those who have this question in mind, Good Job. You have understood the topic very well. Now lets talk about the solution.
If you want to know the file is coming from the right person, ask the person to encrypt the file two times. He will use his private key to encrypt the file first time. Second time he will use your public key to encrypt the already encrypted file.
If a hacker steals the file, he will not be able to read it because he needs your private key. Once you receive the file, you will use your private key to decrypt the first time. You will see the file is encrypted, use the public key of the sender. If the file is decrypted, it means it is from the right person, or else it has been compromised.
I hope you have understood the topic of Public Key vs Private Key in Cryptography. In case you have any questions, don’t hesitate to ask in the comment section.