# Asymmetric Cryptography Deconstructed

###
Simon
*Updated on *
γ»4 min read

Deconstructed (4 Part Series)

# Preface

In my Blockchains Deconstructed article, I mentioned that there are many cool enabling technologies that work together to make Blockchains possible. One of these technologies is `Asymmetric Cryptography`

.

# What is Asymmetric Cryptography

Spy training 101! In order to pass today's lesson, you need to come up with a way to share a secret with the intended recipient (me). Unfortunately for you, you cannot seem to control your voice so anything you say can be heard by everyone. What do you tell me?

A simple solution to this is to tell me the following:

- buy a box with a digital lock (any lock will do, I used a digital lock because it is less confusing)
- keep the pin to unlock the lock to yourself
- keep the box unlocked

In order to share this secret with me without anyone else knowing, you will write the secret on a piece of paper, put it in my box and lock it up. You can be assured that the only one who can unlock the box is me because I am the only one who knows the pin to unlock this box. With this approach, we are all able to share our secrets with one another without exposing the secret itself!

In essence, this is how Asymmetric Cryptography works. Asymmetric Cryptography consists of 2 keys, a public and a private key. The unlocked box is the public key and the pin is the private key. When someone wants to share a secret with me, they would encrypt the secret by putting the secret into my unlocked box and locking it. I can decrypt it by entering the pin into the box and retrieving the secret. Asymmetric Cryptography is sometimes also referred to as Public Key Cryptography.

# Why is it called Asymmetric Cryptography?

For the more curious readers, you might be wondering why this cryptography is called Asymmetric Cryptography and if there exists a Symmetric Cryptography. You are in fact correct; there is another form of cryptography called Symmetric Cryptography and the biggest difference between these 2 types of cryptography is the number of keys.

As described earlier, there are 2 keys in Asymmetric Cryptography. `The public key is used to encrypt something while the private key is used to decrypt it`

. What makes Asymmetric Cryptography even more special is that the inverse is true as well i.e. you can also encrypt something with the private key and this can only be decrypted with the public key. The most common reason for doing this is to prove to someone that that you have access to the private key corresponding to this public key.

Symmetric Cryptography on the other hand uses only *one* key. You encrypt and decrypt with this same key. An intuitive example of this is the lock on your house door. When you leave the house, you lock the door with a key. When you return home, you unlock the door with the same key. Anyone else with access to this key can also lock and unlock the door.

# Example of Asymmetric Cryptography

There are many different types of Asymmetric Cryptography but the most popular and widely adopted is the RSA encryption. The following is an example of a 4096 bit public private key pair generated using the RSA algorithm.

```
###############
# Private Key #
###############
-----BEGIN RSA PRIVATE KEY-----
MIIJKAIBAAKCAgEAu1YltChngFIw86oxjJcvvFpcyfmzyzoT/NSYxR2DZxP49hfkkEtMsHCt5J
xy7zl5vqknziLwGmX+scihG2UYo6zRqsDGr6oQt5Gz23CNSu62jxm7FEGifVT6jxoMwFjV3DYb
DtP5CL4CcAhnRjTuQs0NQmgqiiBBhKFZX4mhs15Bfhev8lkXlpJ9v2kKISeIUxiSMRmcAZnjUV
xU6Z2ljIwIRSKWV7goFf9BGV9tfLPsxPl2PwsJFL2ek+XLwhGXEHKzoUBe3817Ejk0JHxjG0EG
SST6vVDNUtAYit5RMeBhEV5ZaLdU78EDQ15A7q5eghSvHKVEHBbgGwP65GTnB+3wegqppaOo3L
tmicXhhu/LifSCwE0D25fVYTpTCnBgV9gnZwaDhLBfl/eFJ8QQvrSHH5PZDzS00yPu8HAG/yqc
2oKfU7lBhIlv/2GqaKHeQh5vKyWvMV7bXE6dPcjV4hBrDrs1cD7VdyqIvm8LqQPD3s+Yj6Z2Q9
ws09SE9DexOK3OTgeGVEHDT7Wejbb7mQm4u6zbXFKwTWhApz1NLpfMoiMP9Ehkg08I9u8y3IZA
xXFF7/K0UGmNcGYtoQBW3D8s4R1npbR4jyEv+JhQb2s9yOCuVm0nRIMsVQVCBBKXItkU7cWjE3
qxD+9NHiS/XcHJF5DzdlE02s66hszgDhECAwEAAQKCAgAT+OQ+J8yZDqovYCa2MWwibZPU6K01
bnSxEM1UvofC1otFWVjB1XVQnkK7y74pKPyEyi33ORxWBCe6NoSOkiGlWYhk5vaHxd7QY1VEgO
RfZ8HI0dpzF2hGamfoF8PiQdZTCuWpmAnF19QUs6CnCH+aWZgfS1G1tiimBjmsCNVXdSYQVmAo
uzzbjbSgUoeE710GVulHGM7cENb+VpSq72a17Dv5eu2CXpzPc44yMU1P7TLB8UKdCAUo0+pzJB
2sDAoJ8+CYwW8b9yE22Sho92XtguozpCCjTFkHii4DqB4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xkfPEU1OSU=
-----END RSA PRIVATE KEY-----
##############
# Public Key #
##############
ssh-rsa
AAAAB3NzaC1yc2EAAAADAQABAAACAQC7ViW0KGeAUjDzqjGMly+8WlzJ+bPLOhP81JjFHYNnE/
j2F+SQS0ywcK3knHLvOXm+qSfOIvAaZf6xyKEbZRijrNGqwMavqhC3kbPbcI1K7raPGbsUQaJ9
VPqPGgzAWNXcNhsO0/kIvgJwCGdGNO5CzQ1CaCqKIEGEoVlfiaGzXkF+F6/yWReWkn2/aQohJ4
hTGJIxGZwBmeNRXFTpnaWMjAhFIpZXuCgV/0EZX218s+zE+XY/CwkUvZ6T5cvCEZcQcrOhQF7f
zXsSOTQkfGMbQQZJJPq9UM1S0BiK3lEx4GERXllot1TvwQNDXkDurl6CFK8cpUQcFuAbA/rkZO
cH7fB6Cqmlo6jcu2aJxeGG78uJ9ILATQPbl9VhOlMKcGBX2CdnBoOEsF+X94UnxBC+tIcfk9kP
NLTTI+7wcAb/Kpzagp9TuUGEiW//Yapood5CHm8rJa8xXttcTp09yNXiEGsOuzVwPtV3Koi+bw
upA8Pez5iPpnZD3CzT1IT0N7E4rc5OB4ZUQcNPtZ6NtvuZCbi7rNtcUrBNaECnPU0ul8yiIw/0
SGSDTwj27zLchkDFcUXv8rRQaY1wZi2hAFbcPyzhHWeltHiPIS/4mFBvaz3I4K5WbSdEgyxVBU
IEEpci2RTtxaMTerEP700eJL9dwckXkPN2UTTazrqGzOAOEQ==
```

# Use cases for Asymmetric Cryptography

There are 2 general approaches to using Asymmetric Cryptography; as a standalone encryption or in conjunction with other encryption algorithms. Digital signatures is a good example of the former while Transport Layer Security (often referred to as TLS/SSL) is an example of the latter.

Blockchain transactions are a good example of digital signatures. When you want to initiate a transaction, you need to sign the entire payload with your private key. Once your transaction is mined, the miners will validate the integrity of your transaction by trying to recover the public key that corresponds to this signature. If it matches your public key (plus a few other checks), your transaction is valid.

TLS/SSL is a protocol for encrypting communications over a network. The initial communication (the TLS handshake) is where Asymmetric Cryptography is used to authenticate the identity of the website's origin server. Following that, a symmetric key pair (session keys) is generated which i used for all subsequent communication. HTTP + TLS/SSL = HTTPS.

And there you have it, Asymmetric Cryptography deconstructed! Stay tuned for other articles in the `Deconstructed`

series!

Thanks for reading.

Deconstructed (4 Part Series)

## dev.to/you

### Claim your page on DEV before someone else does

### Join DEV Now

Open source

Free forever

Level up every day

π€