I'm totally confused by the public key and private key terms. From my understanding, the "public key" is used for encrypting data, it's more like a lock which can lock something in and only the "private key" (key owner) can unlock it. So why call it "public key", why not call it "public lock"?

If "public key" is the right term and it's referring to key/lock analogy. Then where is the lock? And how these keys, locks work together?

If "public key" is not referring to the key/lock analogy, then could you explain an analogy for me to understand how the asymmetric encryption actually works:
1. when a public key encrypt something, a private key decrypt it
2. when a private key encrypt something, a public key to verify it

  • 9
    The problem is that you are looking at it as an analogy, and not looking at the technology. "Key" is a precise technical term that fits the algorithm involved.
    – schroeder
    Commented May 1, 2015 at 2:42
  • 23
    I think the question is valid. It's unfortunate that this forum is filled with people who seek to limit conversation to narrow categories. Mental models are incredibly important, but often overlooked. The very term "key" IS an analogy, and serves to to inform everyone how the technology works. It's most certainly important. Commented May 1, 2015 at 3:24
  • 9
    Keep in mind that the public / private key-pair can be used in the reverse manner for digital signing; thus the lock analogy is well suited to encryption, but falls apart. The answer provided by @SteveSether accounts for this well. Commented May 1, 2015 at 6:30
  • 12
    Steve - this site is explicitly not a conversation forum. Personally I'd downvote this if I wasn't a mod, as it's irrelevant to security. You could call it an orange if you wanted - it wouldn't change anything.
    – Rory Alsop
    Commented May 1, 2015 at 12:16
  • 8
    To explain the mental model to newbies like me with the right term and analog can help us understand the security theory behind, thus it improve the security of the world. I think it's extremely important to name the terms because that's what newbies will use to comprehend by relating them to the real world. Those who think it doesn't matter what term to call is because you already know the whole picture.
    – Aaron Shen
    Commented May 1, 2015 at 13:14

9 Answers 9


I'm not sure what locks you have experience with, but deadbolt locks are commonly used to lock from the outside. Thus "Lock something in".

In this case, the analogy is that a "key" is something variable, and the "lock" is the algorithm. The lock remains the same, while the key can be changed. In public key cryptography the key used to lock is different from the key used to unlock.

  • 2
    Yes. If you understand this fact, you understand a key (har, har) principle in modern cryptography. Rather than securing something with a secret algorithm (security through obscurity), we use a non-secret algorithm where all of the "secretness" and "variableness" has been condensed to a comparatively small sequence of bytes. The lock-key analogy isn't perfect, but the core idea is that there is an non-variable algorithm and a variable/unique set of data. Commented May 1, 2015 at 14:41
  • 3
    +1 for this: "The lock remains the same, while the key can be changed." That's the main idea behind Kerckhoffs' principle, a system is considered secure if the enemy knows exactly how the lock works (the algorithm), and still can't open the lock if they don't have the key (variable and unique).
    – IQAndreas
    Commented May 1, 2015 at 14:42
  • 1
    The OP is not stupid at all. Still, a public lock would be a better analogy. Public Key cryptography could be very vividly explained with a letter I put into a box I put my lock on, close it with my key, and send it to the receiver. The receiver put their lock on, close it, and send it back to me. I open my lock, and send it back to the receiver. The receiver can then finally open the box and read the message. An eavesdropper always saw a closed box passing by, never could open it. Commented Jul 15, 2016 at 20:29
  • 1
    Then, a public key server could better be called a public lock server. It could be explained that such a server would make the first two steps unnecessary, because I can download the receiver's public lock from such a server and 3D-print it. Commented Jul 15, 2016 at 20:32
  • -1 for "the lock remains the same". It really depends on where you want to root the analogy... you could also start from the lock technology being the algorithm - and you can use the same lock technology "algorithm" to make many different locks and keys. The lock determines what key would open it, just like the "public key" determines what "private key" unlocks it. You techies really want to be a closed club of wizards with only those who can break through the misleading jargon of the status quo being able to join the club? The result? Everyone are still using simple usernames and passwords.
    – Dagelf
    Commented May 10, 2019 at 13:33

The word key was introduced well before asymmetric encryption was even thought to be a thing. In the symmetric context, you use the same key both for encrypting and decrypting, and here the key analogy absolutely makes sense, in that physical keys are often used for both locking and unlocking.

When asymmetric encryption came along, the term key was well established, and the analogy was stretched a bit.

  • 4
    This is the answer I prefer - attempting to ex post facto rationalize the use of "key" for "public key" seems to ignore the historical context. In Diffie and Hellman's seminal paper, the primary motivation for the use of "public key" is that "the user's enciphering key E_k can be made public without compromising [...] security," which was a marked departure from the state-of-the-art. In other words, "public key" means "hey, you know that symmetric key that has to be private? it can be (partially) public now!"
    – Reid
    Commented May 1, 2015 at 12:39
  • Asymmetric keys can unlock things as well, mainly for nonrepudiation purposes, so the analogy may have been stretched at start, but it was snapped back later somewhat.
    – trysis
    Commented May 1, 2015 at 12:48

A piece of music has a key, but no lock. A standardized test has an answer key but no lock. A piano has 88 keys but no locks. A database table key has absolutely nothing to do with a database lock.

A cryptosystem also has keys but no locks. The word key has a dozen or more meanings that have nothing to do with locks.

A key in a cryptosystem is in many senses more like the answer key to a test than it is like a hunk of metal.

  • 1
    This was always my understanding of it. On a map, the key tells you what the symbols represent; in a simple substitution cipher, for example, the key tells you which cleartext character each ciphertext character represents. In a database, the key identifies a certain record (using "key" meaning "important", as in "keyword", or the phrase "timing is key"). In modern asymmetric encryption, the key identifies one particular encryption scheme out of the entire "space" of possible key values. So, the link to keys and locks is merely coincidental; the meaning is somewhere between these two. Commented May 1, 2015 at 14:33
  • 1
    That use of the word key is still figuratively related to the key/lock pair, where the lock is the (obscure) meaning of the symbols on a map, and the key unlocks your understanding of it.
    – UncleZeiv
    Commented May 1, 2015 at 14:38
  • 1
    There some subtlety in the English language here. Some of the other uses of the word key could be translated with different words in other languages, because they represent rather different concepts. The vast majority of documents talking about encryption represent key in the "key+lock" sense, often with accompanying pictures. I've never seen a document about encryption illustrated with a piano, musical or map type of key.
    – Bruno
    Commented May 1, 2015 at 15:28

Locks are typically operated by keys, whether you are locking or unlocking them.

In cryptography, the cipher is the lock. In public-key cryptography, this lock happens to be locked with one key (designated public) and unlocked with a different key (designated private), but neither of those is any less a key for that.

  • Bravo for a succinct and accurate response that is faithful to the key/lock analogy!
    – hashlock
    Commented Nov 1, 2022 at 16:57

This 'problem' is often encountered by people who are just learning about cryptography and public / private key cryptography. So I understand your confusion.

The reason we call both a 'key' is because its cryptographic function is to be a cryptographic key which has nothing to do with common day keys and locks.

In many analogies for laymen the lock - key analogy is used and this is the source of your confusion. You think of the key as something to unlock with. While a cryptologist see a key as a hut of information to encrypt or decrypt a piece of information.

And to keep in your analogy, there are doors that have no handles and these doors you open and close with the key (so the key is used both for opening and closing the door, giving you access to what's inside it).


Asymmetric crypto is made of a private and a public key. The reason for calling both keys, is the fact that you can indeed use either to encrypt and the other to decrypt.

Real world scenarios do exists for this; your signature is encrypted using your private key. Anyone with access to your public key can decrypt the signature to confirm you identity.

The use of encryption/decryption is more in the context of emphasizing a mathematically linked process rather than signifying confidentiality of information.

  • 4
    Nope. You cannot generally encrypt with a private key; signing is not "encryption with the private key" except in horribly insecure versions of RSA that are not used anywhere (RSA needs padding, and the padding to make a secure signature isn't the padding needed to securely encrypt). With other asymmetric encryption schemes, the private key absolutely cannot be used in any sort of encryption operation, and there is no remotely similar signing operation. This answer is taking things which are sort of-not really true for RSA, and applying it to asymmetric schemes in general.
    – cpast
    Commented May 1, 2015 at 10:20
  • @cpast I totally agree. In fact, "encrypting with the private key" and "deciphering with the public key" go against the very definition of the word "encryption", in plain English. If anyone with the public key can "decrypt" the content, then it was never really "encrypted" in the first place, by definition.
    – Bruno
    Commented May 1, 2015 at 15:19
  • 1
    @cpast: Though your point is well-taken -- that in RSA one does not typically encrypt lengthy messages with the private key -- I think it is reasonable to note that the "encrypt a message with the public key" and "produce a signature out of the message hash and a private key" are quite similar when you're actually doing the math. Both involve producing an integer (as either a portion of the message or as the hashed message), raising that to the power of one of the keys, and computing the modulus. Commented May 1, 2015 at 18:40
  • 1
    @Eric First, RSA isn't the only system. Second, padding differences are not trivial; RSA is insecure with bad padding. Third, the mechanics aside, signing is not encryption; in a question about confusing analogies, saying signing is encryption adds to the problem.
    – cpast
    Commented May 1, 2015 at 19:08
  • @cpast: What's important is that given a pair of keys, processing a piece of data with both in sequence will yield the original; in the most basic implementation of something like RSA with a key broken into two equal-length parts, one could keep either part public and public the other part and use the key for either signing or encryption. Unbalancing the lengths of the key components makes many operations faster, but only certain usage patterns will remain secure. I think it's helpful to understand both the general bidirectional pattern, and the reasons it doesn't fit modern usages.
    – supercat
    Commented May 1, 2015 at 19:24

If you have ever operated a personal bank locker, it can be operated through two keys: one is given to the owner and another is kept in the bank. The locker can be locked through a single key that the owner (customer) of the locker possesses. Hence key can be used for locking. For unlocking the locker, the owner needs her key as well as the key possesses by the bank. Just for your own understanding you can assume the owner + bank key to be equivalent of private key while only the owner key is the public key. Also in this case the term public can be used loosely in the same context as well. No matter who possesses the public key, it is of no use if he/she is not in possession of the private key (the key kept in bank) as well.


If that term doesn't suit the bill for you, try substituating it for 'Encryption vector' which is what the key is when encrypting and the inverse 'Decryption vector'. In the end it's just a number though.


A key is for unlocking, right. That's what a public key do, it unlocks the access to the data/material, so it is basically a key to access or unlock the data.

  • A key isn't just used for unlocking, but locking to. Although in the context of cryptography, a different 'key' can be used to lock and unlock.
    – KingJohnno
    Commented May 1, 2015 at 9:44

Not the answer you're looking for? Browse other questions tagged .