This question already has an answer here:

The question is simple. A and B are two parties exchanging information. A has public key p1 and private key pvt1. We know p1 is open for all but pvt1 is not for any one. Now A encrypts file with pvt1 and sends to B. B has p1. B also has his pvt2.

To do a secure transfer of data A uses pvt1 on the file and sends it to B. Now can B decrypt the file with just p1? Does he not need pvt1 as well? Then how this pvt1 will be exchanged? Or if pvt2 is needed to decrypt the file then how do they create pvt1 and pvt2?

Ok. Let me rephrase. I send you data encrypted with pvt1 key. So how do you open this document? Without my pvt1 how can you open? If you can open with your pvt2 key then shouldn't there be a relationship between pvt1 and pvt2 key? Otherwise how can you open my document ?

marked as duplicate by S.L. Barth, Steffen Ullrich, grochmal, Rory Alsop Dec 30 '16 at 16:45

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    You want to know how asymmetric cryptography works? Public key is public, and everyone knows it. Private key is what only you know. Encryption with the private key is "signing" and can be verified/decrypted for anyone with the public key. Encryption with the public key is public key encryption, and only the private key can decrypt. Keys are generated in pairs, and usually one is derived from the other during the generation process. Key sharing is usually done through web of trust or PKI. The former usually involve physical key signing parties, the latter CAs. – Alpha3031 Dec 30 '16 at 5:30
  • I'm vastly simplifying, of course, but it's a complicated topic, and you'll probably have a better time if you tell us what exactly you want to know. – Alpha3031 Dec 30 '16 at 5:31
  • Public and private keys are never really used to encrypt the communication. They are only used in beginning of the handshake. B will use the public key of A to encrypt the symmetric key and A will decrypt the symmetric key using its private key. There is no use of public and private key of B. – defalt Dec 30 '16 at 9:01
  • 2
    @AlanWatch, "never" is a bit too much of a simplification. Certainly it is not generally used when lots of small communications are going on such as the dialogues in HTTPS or FTPS. But they are commonly used directly for encrypting large files for example. – Julian Knight Dec 30 '16 at 11:13

For a secure communication between A & B it is required that they must agree on one symmetric-key which can be used for encryption & decryption.

The problem is simply sending this symmetric key from B to A is not possible because it is visible and can be easily compromised by an attacker. So, B has to encrypt this symmetric key before it can be sent in such a way that only A can decrypt it to see this key.

For that B uses the public key of A (presented by A in the start) to encrypt the content and A uses its private key to decrypt the content. Both of them now have a common key to encrypt and decrypt messages and public and private key pair is no longer required.

There is no use of public and private key of B in the communication. The only work of B is to generate a symmetric key and send it to A. Private key of A is never shared with B.

  • Then please tell me what is the relationship between the private key and private key of A? Is there a common encryption mechanism for both A and B? – Toufiq Alam Dec 31 '16 at 6:17
  • The answer is already given in the original question. The common encryption mechanism is RSA. The relationship between the public and private key of A is public key encrypts the message and private key decrypts it. – defalt Dec 31 '16 at 8:17
  • this answer is actually incorrect - you do not 'need' symmetric encryption to send an encrypted message, symmetric encryption is a lot faster, so it is used when speed is a factor - you also don't address the whole private/public key relationship, which is the point of the question – schroeder Dec 31 '16 at 9:10
  • @schroeder but you do need a symmetric key if a server wants to communicate with a client. Symmetric key is not needed if a communication is only one-way. The question was about how A&B exchange information. During the TLS handshake, web browser generates a symmetric key for further communication. What else I didn't address? – defalt Dec 31 '16 at 9:50
  • You're assuming he meant TLS or even 2-way communication (or even a client/server relationship). The entire content of the question focuses on the relationship between the keys. It looks like you completely missed the question. – schroeder Dec 31 '16 at 14:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.