| |
Algorithms, classes, and methods | page 3 of 5 |
The following two algorithms are used in public key encryption: - RSA. This algorithm is the most popular public key cipher, but it's not supported in JDK 1.4. You must use a third-party library like BouncyCastle to get this support.
- Diffie-Hellman. This algorithm is technically known as a key-agreement algorithm. It cannot be used for encryption, but can be 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.
The Cipher class manipulates public key algorithms using keys produced by the KeyPairGenerator class. The following methods are used in the Public key cryptography code example example: - KeyPairGenerator.getInstance("RSA"), .initialize(1024), and .generateKeyPair(): Generates the key pair.
- Cipher.getInstance("RSA/ECB/PKCS1Padding") Creates a Cipher object (specifying the algorithm, mode, and padding).
- .init(Cipher.ENCRYPT_MODE, key.getPublic()): Initializes the Cipher object.
- .doFinal(plainText): Calculates the ciphertext with a plaintext string.
- .init(Cipher.DECRYPT_MODE, key.getPrivate()) and .doFinal(cipherText): Decrypts the ciphertext.
|