Public Key cryptography is based on asymmetric encryption. Asymmetric encryption makes use of a mathematically linked pair of keys, one is known as the public and the other is known as the private key. The plaintext encrypted using one of the keys can only be decrypted using the other key, and it is impossible to compute private key, if public key is published. A user has his own pair of keys, keeping the private key absolutely private and the public key as public as possible.
The following text explains the concept more clearly. If Alice has in hand her own public key (PubA), her own private key (PrivA), and Bob's public key (PubB), she can do the following:
• Encrypt the plaintext with Bob's public key (PubB)
• Calculate the hash sum of the plaintext and encrypt it with her own private key (PrivA)
• Combine the ciphertext and the encrypted hash sum in a message and send it to Bob.
Upon receiving this message, Bob, who should have in his possession his own public key (PubB), his own private key (PrivB), and Alice's public key (PubA), can do the following:
• Decrypt the ciphertext with his own private key (PrivB)
• Decrypt the hash sum with Alice's public key (PubA)
• Calculate the hash sum of the plaintext and compare it with the decrypted hash sum
Bob can now decrypt the ciphertext to plaintext and, if the hash sums are the same he can make sure that it hasn't been altered in network.