A Complete Guide on How Public-Key Cryptography works.
Tags: showdev, blockchain, career
Published: 2019-12-26 08:38:46


Cryptography makes Blockchain more robust and stands out from other technology. Cryptography which uses advance mathematical principles method in transmitting and storing the data, it stores in a way that only the person for whom the data is intended can read and process it.


"Encryption is the core concept in cryptography- It encodes the message in a way that no one can decrypt it except the receiver, it keeps the data safe from an eavesdropper, where they cannot read and understand the format".

Quick intro of this technique, this was first used by Caesar to encrypt his messages using Caesar cipher, where a plain text is encrypted to cipher text and then send through the communication channel and no eavesdropper can read and understand the text. When it receives at the receiver end it decrypted to plain text from the cipher text.
There are two types of Cryptography

1. Symmetric cryptography

2. Asymmetric cryptography


__Symmetric cryptography__
Symmetric cryptography is same as the Caesar Cipher Technique, where uses a single key to encrypt and decrypt the data. I have created a visualization of this process for a better idea.

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/31bf1spvxeokkp0x7m5a.png)

But Symmetric Cryptography has some drawbacks

Both persons should have to use the same key, there is no problem of using the same key but the problem comes, when we want to share the key from an eavesdropper, this is the difficult task.

We are using the Symmetric Cryptography for the safe transfer of the data from eavesdroppers, but we have to share the key to the receiver person. If the receiver is living by we can give it to him directly in an envelope or other sources, what if the person is from a different state or country. It becomes difficult, so to overcome this problem there is one more technique called Asymmetric Cryptography.

This Asymmetric Cryptography, we use in Blockchain Technology.


__Asymmetric Cryptography__

Asymmetric Cryptography makes the Blockchain technology more Robust mechanism and solves the drawback of Symmetric Cryptography.


"Asymmetric Cryptography is a bit more complex than the Symmetric Cryptograph and the main difference between these both his, Symmetric uses the shared key to decrypt the data and Asymmetric uses Key-pairs to decrypt the data".

Key pairs consists of 2 parts, a public key and a private key.

Let’s take an example of Gmail If we need to send a mail to the person or company.

1. Every user in Gmail has specially allocated username and a password.
2. They use the Receiver’s username to send the data to them.
The receiver receives the message from the sender and reads the data.
3. The same process applies with Asymmetric Cryptography,

"Every user has Public key which is same as your username, Every person can see this but don’t have access to the data and Private key is same as your password, which helps you to send the data to another person".

__To the send the data first we will use the private key (i.e password) and receivers public key(i.e username) this makes the cryptography technique more complex.__

__Now receiver uses his private key (i.e password) and senders public key (i.e username) to decrypt the data. This makes the system safe from eavesdropper and more robust.__

There is no need to have an intermediate and we can send to any person in this world.

I have created a visualization of this process for a better idea.

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/czlg0antgbk9x87y0o39.png)

__Digital Signatures__

Now when we send a mail through my mail id the receiver knows that I have sent to him by seeing the username. I cannot send the data without password i.e if any mail you’re sending through your username, you’re responsible for that. No once can access your account without the password.

In the same way without the private key, no one can send a message through your public key, if any message you have sent through it your responsibility for that because without private key no one can send the message through your address. We have to be more careful because for Gmail we have a central database to retrieve your password but Blockchain is decentralized, you need to keep your private key more safely.

When we send data using our privet key, it is signed by our Digital Signature and it allows non-repudiation as it means the person who sent the message had to be in possession of the private key.

"If you encrypt (“lock”) something with your private key, anyone can decrypt it (“unlock”), but this serves as a proof you encrypted it: it’s “digitally signed” by you. — PanayotisVryonis"