Public key cryptography (also known as asymmetric key cryptography)
J2SE 1.4.x supporting algorithms: RSA, DH
Using public key cryptography, Alice wants to send an encrypted message to Bob using the following simple protocol:
Alice and Bob both have their own key pairs. A key pair consists of a public key and a private key. If the public key is used to encrypt something, then it can only be decrypted using the private key. And similarly, if the private key is used to encrypt something, then it can be decrypted only using the public key. It is not possible to figure out what the private key is given only the public key, or vice versa.
Alice wants to send an encrypted message to Bob. She encrypts the message (=plaintext) using Bob's public key and sends the encrypted message (=ciphertext) to Bob.
Bob receives the encrypted message and decryptes if it with his private key to to re-create the original message.
RSA is supported by J2SE 1.4. However to make this work you need a third-party library like BouncyCastle.
The Diffie-Hellman (DH)algorithm, also known as key-agreement algorithm is used to allow two parties to derive a secret key by sharing information over a public channel. This key can then be used for private key encryption.