Question : Public and Private Keys - how does it work

I'm still not clear on how this works although I made various research on the net. One simple question.  If Computer-A wants to send to Computer-B. Which key does Computer-A use?

It's own private-key to encrypt data?
or
Computer B public-key to encrypt data?

In my opinion it should be Computer B public-key as otherwise any other computer/sniffer could be able to decrypt the message through Computer A public key if this was encoded using Computer-A's private key....

Very confusing..................

Answer : Public and Private Keys - how does it work

If Computer-A wants to send to Computer-B. Which key does Computer-A use?

- It really depends on what you want to do for the Public Key Infrastructure. Are you doing Signature (to maintain data integrity to detect tampering) OR encryption (to maintain data confidentiality to avoid leakage) OR Key exchange (maintain unique session protection establishment) .

For encryption, definitely as mentioned by others, it is logical to get the intended recipient (Rx) party's PUBLIC cert (that is why it is called) and on his/her receipt, he/she will use his/her PRIVATE key to decrypt. This is the asymmetric way of key handling (as compared to symmetric that use common keys, either self generated or pre-shared).  

For signature, sender (Sx) will use PRIVATE key as it represent himself/herself. The intent is to ensure non-repudiation (in short they cannot deny that the data is not from them) and integrity (knowing the data is not tampered and is in its original form). The Rx will then 'decrypt' it using the Sx's PUBLIC key to validate the this.

For Key exchange, you can view it as using the 'encryption' scheme to exchange some parameters that eventually can be used to generate a session key (Secret) for protecting the subsequent data exchange. Why so? the 'encryption' scheme (or the asymmetric) is slower as compared to session key (or symmetric), hence it is typically used for encryption small data size (e.g. those parameters).

Having said that, there is really no stopping anyone to use either of the key for encryption but just that their intent will differ based on their usage scenario. Of course note the scheme need to be complemented with PKI concept with Certificate Authority in the picture to ensure the key are really from trusted party as well (asymmetric scheme does not integrity of the keys itself).

Maybe a little simple doc as attached may be useful for understanding    

Hope it helps to clarify your doubts
In my opinion it should be Computer B public-key as otherwise any other computer/sniffer could be able to decrypt the message through Computer A public key if this was encoded using Computer-A's private key....


 
Encryption Vs Signature
 
Random Solutions  
 
programming4us programming4us