---
title: How Does Public Key Encryption Work? | Public Key Cryptography and SSL
description: Public key encryption, also known as public key cryptography, uses two cryptographic keys: a public key and a private key. It makes TLS/SSL possible.
image: https://www.cloudflare.com/preview.png
---

##  How does public key cryptography work? 

 Public key cryptography, also known as asymmetric cryptography, uses two separate keys instead of one shared one: a public key and a private key. Public key cryptography is an important technology for Internet security. 

######  Learning objectives 

 After reading this article you will be able to: 

* Define public key cryptography
* Understand how public key cryptography works
* Learn why public key cryptography is essential for the TLS/SSL protocol

 Related content 

On this page 

## What is public key cryptography?

Public key cryptography is a method of encrypting or signing data with two different keys and making one of the keys, the public key, available for anyone to use. The other key is known as the private key. Data encrypted with the public key can only be decrypted with the private key. Because of this use of two keys instead of one, public key cryptography is also known as [asymmetric cryptography](/learning/ssl/what-is-asymmetric-encryption/). It is widely used, especially for [TLS/SSL](/learning/ssl/transport-layer-security-tls/), which makes [HTTPS](/learning/ssl/what-is-https/) possible.

Sign up

Security & speed with any Cloudflare plan

[Start for free →](/plans/)

## What is a cryptographic key?

In cryptography, a [key](/learning/ssl/what-is-a-cryptographic-key/) is a piece of information used for scrambling data so that it appears random; often it's a large number, or string of numbers and letters. When unencrypted data, also called plaintext, is put into a cryptographic algorithm using the key, the plaintext comes out the other side as random-looking data. However, anyone with the right key for decrypting the data can put it back into plaintext form.

For example, suppose we take a plaintext message, "hello," and encrypt it with a key; let's say the key is "2jd8932kd8." Encrypted with this key, our simple "hello" now reads "X5xJCSycg14=", which seems like random garbage data. However, by decrypting it with that same key, we get "hello" back.

Plaintext + key = ciphertext:

```
hello + 2jd8932kd8 = X5xJCSycg14=

```

Ciphertext + key = plaintext:

```
X5xJCSycg14= + 2jd8932kd8 = hello

```

This is an example of symmetric cryptography, in which only one key is used. In public key cryptography, there would instead be two keys. The public key would encrypt the data, and the private key would decrypt it.

Whitepaper

Maximize the power of TLS

[Read the whitepaper →](/lp/maximize-tls/)

## How does TLS/SSL use public key cryptography?

Public key cryptography is extremely useful for establishing secure communications over the Internet (via HTTPS). A website's [SSL/TLS certificate](https://www.cloudflare.com/application-services/products/ssl/), which is shared publicly, contains the public key, and the private key is installed on the [origin server](/learning/cdn/glossary/origin-server/) — it's "owned" by the website.

[TLS handshakes](/learning/ssl/what-happens-in-a-tls-handshake/) use public key cryptography to authenticate the identity of the origin server, and to exchange data that is used for generating the session keys. A key exchange algorithm, such as RSA or Diffie-Hellman, uses the public-private key pair to agree upon session keys, which are used for symmetric encryption once the handshake is complete. Clients and servers are able to agree upon new session keys for each communication session, so that bad actors are unable to decrypt communications even if they identify or steal one of the session keys from a previous session.

```json
{"@context":"https://schema.org","@type":"Organization","name":"Cloudflare","url":"https://www.cloudflare.com","logo":"https://www.cloudflare.com/logo.svg","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"]}
{"@context":"https://schema.org","@type":"WebSite","name":"Cloudflare","url":"https://www.cloudflare.com","inLanguage":"en","potentialAction":{"@type":"SearchAction","target":"https://www.cloudflare.com/search?q={search_term_string}","query-input":"required name=search_term_string"}}
{"@context":"https://schema.org","@type":"WebPage","name":"How Does Public Key Encryption Work? | Public Key Cryptography and SSL","description":"Public key encryption, also known as public key cryptography, uses two cryptographic keys: a public key and a private key. It makes TLS/SSL possible.","url":"https://www.cloudflare.com/learning/ssl/how-does-public-key-encryption-work/","inLanguage":"en"}
```
