# Symmetric vs Asymmetric encryption

The most common types of encryption are Symmetric encryption and Asymmetric encryption. Let’s see how they differ.

### Symmetric encryption

This encryption uses only one key for both encryption and decryption. Let’s say you want to share a secret data with your friend. In symmetric encryption, both you and your friend will have a common key known as the secret key. You will use this secret key to encrypt the data that you want to share with your friend and then send this encrypted data through the internet without worrying about spying on it by some third party. Since your friend also has the same secret key that you have, he can then decrypt the data using that key.

let’s call `E` as the encryption algorithm, `D` and the decryption algorithm, `P` as the plain data, `K` as the secret key and `C` as the cipher or encrypted data then the whole process of symmetric encryption can be described as:

`E(P, K) = C`
`E` takes `P` and `K` as the input and produces `C` as the output

`D(C, K) = P`
`D` takes `C` and `K` as the input and produces `P` as the output

The risk involved in symmetric encryption is sharing the secret key itself. If the other person you want to share the secret message with doesn’t have the secret key, you will need to share the secret key first and it is a risky job because if somehow your secret key got leaked, your data is not private anymore.

### Asymmetric encryption/ PublicKey

In asymmetric encryption, two keys are involved i.e. public key and private key. The public key encrypts the data and only the private key of the corresponding public key can decrypt the data. Public key is safe to be shared with anyone because no one can decrypt the data if he doesn’t have the private key – to send secret data, you must have the recipient’s public key so that only he can decrypt the data using the corresponding private key of the public key.

`A` wants to send a secret message to `B`. Both `A` and `B` will have their own set of public and private keys.`A` will ask `B` for his public key, `A` will encrypt the secret message with this public key and send the encrypted data to `B`, finally `B` can decrypt the message using his private key.

let’s call `E` as the encryption algorithm, `D` and the decryption algorithm, `P` as the plain data, `PB` as the public key, `PR` as the private key, and `S` as the encrypted message then the whole process of asymmetric encryption can be described as:

`E(P, PB) = S`
`E` takes `P` and `PB` as the input and produces `S` as the output

`D(S, PR) = P`
`D` takes `S` and`PR` as the input and produces `P` as the output

Asymmetric encryption is usually slower than symmetric encryption but more secure than it