Skip to content

Public and Private Keys

Module 2 of 7 in the shared chapter Keys, Certificates and Trust, chapter 3 of Securing Salesforce: Identity and Access and chapter 12 of Integration Architect. Each module stands on its own.

The question this module answers: How can two sides that have never met share a secret, when every message between them can be read?

In module 1, the village learned to encrypt its messages. Every message on the road can be read and copied by the bandits, so the village scrambles each one with a strong, public algorithm and a long, secret key. The bandits copy the encrypted text and learn nothing.

But there was a catch. The town has to hold the same key to read the message. One key, used to lock and to unlock: that’s symmetric encryption.

So here’s my question. What is the problem with one key, when the two sides are far apart?

The key has to be shared. And the only road between the village and the town belongs to the bandits. If the rider carries the key, the bandits copy it, and every message they ever took can now be read.

Think of the village as your browser and the town as a website it has never visited. Or Salesforce, calling a system on the other side of the world for the first time. They have never met. There’s no one to carry the key safely. How do they start?

This is where the experts in cryptography come back into the story, the same smart PhDs who gave us the strong algorithms. They came up with a new idea, and it’s a strange one the first time you hear it.

An algorithm with two keys. Not two copies of one key: two different keys, made together, as a pair. One key locks, and the other key unlocks. And it works both ways round.

Here’s the rule. If a message is locked with the first key, only the second key can unlock it. If it’s locked with the second key, only the first key can unlock it. Once a message is locked with one key, it cannot be unlocked with that same key.

Because the two keys are different, this is called asymmetric encryption, the opposite of module 1’s symmetric, one-key encryption.

Let’s give the two keys names. One is the silver key: this is the public key, and it’s meant to be given out. The other is the gold key: this is the private key, and it never leaves its owner. Locked with silver, only gold opens it. Locked with gold, only silver opens it.

Who makes the pair? The side that will keep the gold key. The town makes both keys, keeps the gold one, and the gold key never travels. Not on the road, not with a rider, not ever.

How the mathematics does this is the experts’ work, and you don’t need it to design with it. What you need is the rule, and what each direction gives you.

Here’s the rule as a picture, with no village and no bandits yet: one key encrypts, the other decrypts, in either direction.

Two keys: the mechanism Three columns from left to right: the silver key, the encrypted text and the gold key, with one row for each direction. Top row, going right: clear text is encrypted with the silver key, the public key; the encrypted text can't be decrypted with the silver key; it is decrypted with the gold key, the private key, and becomes clear text again. Bottom row, coming back left: clear text is encrypted with the gold key, the private key; the encrypted text can't be decrypted with the gold key; it is decrypted with the silver key, the public key, and becomes clear text again. Underneath: one key encrypts, the other decrypts, in either direction; the key that encrypted a message can't decrypt it. {"author": "Steve Simpson", "blueprint": "1.0.0", "builder": "standard 1.57.1", "built": "2026-11-01", "id": "DGM-IAM-TR-04", "rights": "\u00a9 2026 Twinshark LLC. All rights reserved.", "template": "cells 0.5.0", "theme": "stevetecharc 1.4.0"} THE SILVER KEY ENCRYPTED TEXT THE GOLD KEY Encrypt with the silver key the public key Encrypted text the silver key can't decrypt it Decrypt with the gold key the private key: the clear text again Encrypt with the gold key the private key Encrypted text the gold key can't decrypt it Decrypt with the silver key the public key: the clear text again encrypt decrypt encrypt decrypt One key encrypts, the other decrypts, in either direction. The key that encrypted a message can't decrypt it. HOW TO READ IT the two keys: silver on the left, gold on the right encrypted text encrypting © 2026 Twinshark LLC · stevetecharc.com
Click to enlarge

So the town does something that sounds wrong after module 1. It sends its silver key out on the road, on purpose. It tells the world: here is my public key, take a copy.

The bandits stop the rider and copy the silver key, just as they copy everything. Now, what can the bandits do with it?

They can lock a message to the town, like anyone else can. But they can’t open one. A message locked with the silver key opens only with the gold key, and the gold key is in the town.

So the village takes Gold leaves Friday by the mountain road and locks it with the town’s silver key. The rider carries it. The bandits stop him, copy the locked message, and try their copy of the silver key on it. Nothing. The silver key that locked it can’t unlock it. The rider rides on, and the town opens the message with its gold key.

Think about what just happened. The village and the town never met. Nobody carried a secret key down the road. And still the village sent the town a secret the bandits can’t read. Anyone, even a stranger the town has never heard of, can now send the town a secret.

Now turn it around. The town locks a message with its gold key and sends it to the village.

Who can read it?

When I asked this in a class, the first answer was “only the town”. Look at the rule again. Locked with gold, only silver opens it. And who has the silver key? The village. And the bandits. And anyone else who asked for a copy, because the town gave it to the world.

So a message locked with the gold key is not a secret at all. Anyone can open it.

Then why would the town ever do it? Here’s the clever part. Only one place in the world holds the gold key. If the town’s silver key opens a message, that message must have been locked with the town’s gold key. So it must have come from the town. Not secret, but proof of who sent it.

Hold on to that. In module 3, that proof becomes a signature, and it’s the root of almost everything in identity.

We’re building a bridge, and we’re halfway there.

This is the part people most often get backwards, so let’s put the two directions next to each other.

You’ve seen the mechanism. Here are the same two rows, told with the village, the town and the bandits:

Locked withOpened withWho can read itWhat it gives you
The village to the townthe town’s silver keyonly the town’s gold keyonly the towna secret, to whoever holds the gold key
The town to the villagethe town’s gold keythe silver keyanyone with the silver keyproof it came from the town

Same two keys, two different messages, two directions, two different results. Lock with silver for a secret; lock with gold for proof.

Both directions, side by side Three areas from left to right: the village, the road (the network) and the town, with one row for each direction. Top row, going to the town: the village locks GOLD LEAVES FRIDAY BY THE MOUNTAIN ROAD with the town's silver key; on the road the bandits copy it, but their silver key can't open it; in the town it is opened with the gold key, so only the town can read it: a secret. Bottom row, coming back to the village: the town locks a different message, THE TOWN IS READY, with its gold key; on the road the bandits copy it and open it with their silver key, so anyone can read it; in the village it is opened with the silver key: not a secret, but proof that only the town could have locked it. Underneath: same two keys, two directions, two results; lock with silver for a secret, lock with gold for proof. {"author": "Steve Simpson", "blueprint": "1.0.0", "builder": "standard 1.57.1", "built": "2026-11-01", "id": "DGM-IAM-TR-03", "rights": "\u00a9 2026 Twinshark LLC. All rights reserved.", "template": "cells 0.5.0", "theme": "stevetecharc 1.4.0"} THE VILLAGE THE ROAD: THE NETWORK THE TOWN Locked with silver GOLD LEAVES FRIDAY BY THE MOUNTAIN ROAD, locked with the town's silver key The bandits copy it their silver key can't open it Opened with gold only the town can read it: a secret Locked with gold a different message: THE TOWN IS READY, locked with the town's gold key The bandits copy it and open it with their silver key: anyone can read it Opened with silver not a secret, but proof: only the town could have locked it to the town rides on to the village rides on Same two keys, two directions, two results. Lock with silver for a secret. Lock with gold for proof. HOW TO READ IT the two ends of the road locking a message the bandits: they copy everything a secret: only the gold key opens it proof: it came from the town © 2026 Twinshark LLC · stevetecharc.com
Click to enlarge

Let’s go back to the town and play the whole story through, frame by frame: the town makes its pair, the silver key goes out, a secret travels one way, proof travels the other.

Two keys, silver and gold Three areas from left to right: the village, the road (the network) and the town, as in the village diagram before it. In the first frame, the town makes a key pair: the gold key, the private one, stays in the town and never travels; the silver key, the public one, is given to anyone who asks. The town sends its silver key out on purpose with the rider, who rides on to the village. On the road, the bandits stop the rider and copy the silver key, but it can lock, never open. In the second frame, the village locks GOLD LEAVES FRIDAY BY THE MOUNTAIN ROAD with the town's silver key and sends it; the bandits copy the locked message, and their silver key can't open it; in the town, only the gold key opens it. In the third frame, the town locks a message with its gold key and sends it to the village; the bandits open their copy with the silver key, so anyone can read it; the village opens it with the silver key too, which proves it came from the town. In the last frame, two amber cards: secrets go one way, to the town but not from it; and whose silver key is it, since it came down the bandits' road? Underneath: locked with silver, only gold opens it, so anyone can send the town a secret; locked with gold, anyone opens it, proof it came from the town; secrets still go one way. {"author": "Steve Simpson", "blueprint": "1.0.0", "builder": "standard 1.57.1", "built": "2026-11-01", "id": "DGM-IAM-TR-02", "rights": "\u00a9 2026 Twinshark LLC. All rights reserved.", "template": "cells 0.5.0", "theme": "stevetecharc 1.4.0"} THE VILLAGE THE ROAD: THE NETWORK THE TOWN The village has never met the town The town makes a key pair: silver and gold Gold key: private stays in the town · never travels Silver key: public given to anyone who asks The bandits stop the rider, copy everything, let him ride on The town's silver key a copy, in the village Locks with gold a message to the village, locked with the gold key The rider carries: a message locked with gold The bandits' copies opened with their silver key: anyone can read it Opens with silver not a secret, but proof: it came from the town Secrets go one way to the town: secret · from the town: anyone can read Whose silver key? it came down the bandits' road: is it really the town's? Locked with silver, only gold opens it: anyone can send the town a secret. Locked with gold, anyone opens it: proof it came from the town. Secrets still go one way. HOW TO READ IT the two ends of the road the bandits: they read and copy everything locking a message what opening it proves the secret: the gold key not quite there yet © 2026 Twinshark LLC · stevetecharc.com
Click to enlarge

Now let’s add up what the village has.

  • It can send the town a secret. Lock with silver; only gold opens. In fact anyone with the silver key can: we now have a one-way encrypted path to whoever made the pair and kept the gold key. That’s important, and the rest of this chapter builds on it.
  • It can tell that a message came from the town. Lock with gold; silver opens, and only the town could have locked it.

That’s a real piece of the puzzle. But can the town send the village a secret?

No. Anything the town locks with its gold key, anyone with the silver key can open, and the bandits have the silver key. The secrets go one way: from the village to the town, and not back. We’re not quite there yet.

There’s one more thing. Two keys are slower to use than one shared key; symmetric encryption is much faster for the work of encrypting every message. So the two keys are rarely used for the messages themselves. But a one-way secret is enough for something very useful: the village can make a fresh shared key and send it to the town, locked with the town’s silver key. Then both sides hold the same key, and the bandits never saw it. That’s where the puzzle is going, and module 5, the handshake that protects the web, puts it together.

The two-key mathematics works very differently from module 1’s algorithms, and it needs much longer keys for the same strength. The US standards body NIST publishes a table that compares them: a two-key RSA key of 3072 bits is rated about as strong as a 128-bit AES key. Salesforce’s own certificates use keys of 2048, 3072 or 4096 bits. So when you see a 2048-bit key next to a 128-bit key, the bigger number isn’t the stronger key. They’re measured on different scales.

From silver and gold to public and private

Section titled “From silver and gold to public and private”

Silver and gold have done their job. From here on, let’s use the names you’ll see everywhere else: the silver key is the public key, and the gold key is the private key. Same two keys, same rule. Locked with the public key, only the private key opens it. Locked with the private key, the public key opens it, and that proves who locked it.

Now, how does the town actually hand out its public key? Not as a bare key. A key on its own is just a very long number, and a number doesn’t say whose it is. So the town puts its public key in a small document with its name on it. That document is a digital certificate.

The certificate and the private key belong together, as a pair. The certificate holds the public key and goes out to the world. The private key is its partner: it never goes in the certificate, and it never leaves the town. When people say “install the certificate” on a server, they mean the pair: the certificate the world sees, and the private key kept hidden beside it.

Let’s open one up. Here’s an example certificate for the town’s website, town.example, with the parts that matter now. (.example is a name set aside for examples; no real site uses it.)

FieldExampleWhat it means
Subjecttown.exampleWho this certificate is for: whose public key this is
Other namestown.example, www.town.example (opens in a new tab)Every name the certificate covers
Public keyRSA, 3072 bitsThe silver key itself, the long number the world uses
Valid from2026-11-01The first day it can be used
Valid to2027-05-19The last day. Every certificate is made to expire (module 7)
Serial number04:A1:9C:…A unique number, so this one certificate can be named
Issuer(someone who vouches for the town)Who says this really is the town’s key. That’s module 4
Signature(a long string of characters)The issuer’s proof that nothing in here was changed. That’s module 3

Look at the first three rows: a name, and a public key. That’s the heart of it. A certificate says, “this public key belongs to this name”. The rest says for how long, and who stands behind the claim.

You can open real ones yourself. Most browsers let you click the icon beside the address and view the site’s certificate. Try it on a site you use every day, and you’ll find these same fields. The format is a standard called X.509 (the IETF’s RFC 5280).

A certificate, opened up Three areas from left to right: the village, the road where the certificate travels, and the town. In the town, the town makes the key pair: the certificate and its private key. The private key, the gold key, is never in the certificate and stays in the town; it is paired with the public key in the certificate. On the road, the certificate is opened up field by field: who it's for (town.example, and www.town.example); the public key, the silver key, RSA 3072 bits; how long (valid 2026-11-01 to 2027-05-19, with a serial number); and who vouches (the issuer and the signature, still to come in modules 3 and 4). The certificate is sent to anyone: the village gets it, the town's public key with the town's name on it. Below it on the road, the bandits copy it too, and that's fine, because it's public. Underneath: a certificate is a public key with a name on it; it goes out to the world, and its private key stays home. {"author": "Steve Simpson", "blueprint": "1.0.0", "builder": "standard 1.57.1", "built": "2026-11-01", "id": "DGM-IAM-TR-05", "rights": "\u00a9 2026 Twinshark LLC. All rights reserved.", "template": "cells 0.5.0", "theme": "stevetecharc 1.4.0"} THE VILLAGE THE ROAD: THE CERTIFICATE TRAVELS THE TOWN The town makes the key pair: the certificate and its private key The private key the gold key · never in the certificate · stays in the town Who it's for subject: town.example · other names: www.town.example The public key the silver key · RSA, 3072 bits How long valid 2026-11-01 to 2027-05-19 · serial number 04:A1:9C:… Who vouches issuer and signature: modules 3 and 4 The village gets the certificate: the town's public key, with the town's name on it The bandits copy the certificate too: it's public, so that's fine a pair sent to anyone A certificate is a public key with a name on it. It goes out to the world; its private key stays home. HOW TO READ IT the two ends of the road the public key: shared with the world the private key: kept hidden still to come: modules 3 and 4 the bandits © 2026 Twinshark LLC · stevetecharc.com
Click to enlarge

You’ll meet this pair the first time you open Certificate and Key Management in Setup. When you create a self-signed certificate there, Salesforce makes the key pair inside your org: the certificate and its private key.

The certificate you download, a .crt file, holds the public key. You can hand it to any system you like; that’s what it’s for. The private key stays in the org. It leaves only if someone exports a keystore: Salesforce lets you “export all your certificates and private keys into a keystore” to “move keys from one organization to another” (Certificates and Keys (opens in a new tab), Salesforce Help, checked 2026-11-07). So treat an exported keystore file like the private key itself.

So the keystore export is the moment to watch. Sharing the certificate is not a leak; it’s the public key, made to be shared. Exporting the keystore takes the private key out of the org. Module 7 shows how Salesforce stores and replaces both.

One more question, and it’s the one the bandits are already asking.

The village locked its secret with the public key in “the town’s” certificate. But where did the village get that certificate? It came down the road, past the bandits. And a certificate is only a document: anyone can write “town.example” on one, and put their own public key inside.

What if the bandits stopped the rider, kept the town’s certificate, and handed on one of their own instead, with the town’s name on it, their own public key inside, and the private key to match in their pocket? The village would lock its secret with the bandits’ public key, believing it was the town’s. The bandits would open it, read it, lock it again with the town’s real public key, and send it on. The town would never know.

That’s called a man-in-the-middle attack: someone sitting between the two sides, pretending to each one to be the other.

So how does the village know the certificate really belongs to the town, and that nobody changed it on the way? Two keys can’t answer that on their own. First, module 3 gives us the tool: hashes and signatures, built from the “proof it came from the town” we found above. Then module 4, “Hang up and call the bank”, shows who vouches for a certificate, and why we believe them.

  • The private key never leaves its owner. Where it lives, and who can export it, is the design decision.
  • Public keys are meant to be shared. Handing out a certificate is not a leak.
  • A certificate is a public key with a name on it. It goes out to the world; its private key stays home.
  • A public key is only useful if you know whose it is. Who vouches is module 4.
  • Two keys are a piece of the puzzle, not the whole answer. One-way secrets and proof of the sender; the handshake in module 5 finishes it.