JDK Tutorials - Herong's Tutorial Notes
Dr. Herong Yang, Version 4.32, 2006

JCA - Private and Public Key Pairs

Part:   1   2  3  4 

JDK Tutorials - Herong's Tutorial Notes © Dr. Herong Yang

Internationalization

Character Set and Encoding

Socket Communication

Document Object Model (DOM)

XSD Validation in Java

XSL - Transformer in Java

JCA - Private and Public Key Pairs

JCE - Secret Key

SSL (Secure Socket Layer)

SSL - Client Authentication

... Table of Contents

This chapter describes some parts of the JCA (Java Cryptography Architecture) which has been included in JDK since 1.1:

  • What are private and public key pairs?
  • Classes in JDK to generate private and public key pairs.
  • A sample program on generating private and public key pairs.

Sample programs listed in this chapter have been tested with JDK 1.3.1, 1.4.1 and 1.5.0.

What Are Private and Public Key Pairs?

Private and public key pairs are used in public key encryption algorithms.

Known private and public key pair generation algorithms are:

  • RSA - Developed by MIT professors: Ronald L. Rivest, Adi Shamir, and Leonard M. Adleman in 1977.
  • DSA - The Digital Signature Algorithm.
  • DiffieHellman

The Key Interfaces

Private and pubic key pairs are represented 3 interfaces.

1. java.security.Key is the interface acting as a base to support common features of both private key and public key. Major methods include:

getAlgorithm() - Returns the algorithm name used to generate the key.

getEncoded() - Returns the key as a byte array in its primary encoding format, or null if this key does not support encoding.

getFormat() - Returns the name of the primary encoding format of this key, or null if this key does not support encoding.

2. java.security.PrivateKey is the interface representing a private key. It extends java.security.Key interface with no additional methods.

3. java.security.PublicKey is the interface representing a public key. It extends java.security.Key interface with no additional methods.

The KeyPair Class

java.security.KeyPair is a final class representing a key pair (a public key and a private key). Major methods in the MessageDigest class:

getPrivate() - Returns a PriviateKey object representing the private key in the key pair.

getPublic() - Returns a PublicKey object representing the public key in the key pair.

The KeyPairGenerator Class

java.security.KeyPairGenerator is an abstract class providing a link to implementation classes of private and public key pair generration algorithms provided by various security package providers. Major methods in the KeyPairGenerator class:

getInstance() - Returns a KeyPairGenerator object of the specified algorithm from the implementation of the specified provider. If provider is not specified, the default implementation is used. This is a static method.

initialize() - Initializes the key pair generator with the specified key size.

generateKeyPair() - Generates a key pair and returns a KeyPair object.

getAlgorithm() - Returns the algorithm name of the current key pair generator object.

getProvider() - Returns the provider as a provider object of the current key pair generator object.

(Continued on next part...)

Part:   1   2  3  4 

Dr. Herong Yang, updated in 2006
JDK Tutorials - Herong's Tutorial Notes - JCA - Private and Public Key Pairs