The technology that drives all of this is known as Public Key Infrastructure, or PKI. Anyone can use the Public Key, but only the holder of the Private Key can use this Private Key — it should never be shared. If someone wants to send me a private/encrypted email message, they simply use my Public Key to encrypt the message before sending. Since only I have the Private Key, only I can decrypt the message to see the original contents.