JDK (Java Development Kit) Tutorials
Dr. Herong Yang, Version 5.00

Private and Public Keys and Related Interfaces

This section describes private and public key pairs used in RSA and DSA encryption algorithms. JDK supports private and public keys with the java.security.Key interface.

What a private and public key pair? A private and public key pair is a private key and a public key used in a public key encryption algorithm.

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

JDK supports private and pubic key pairs with 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.

Last update: 2006.

Sections in This Chapter

Private and Public Keys and Related Interfaces

KeyPair and KeyPairGenerator Classes

Key Pair Sample Program - JcaKeyPair.java

DSA Private Key and Public Key Pair Sample

RSA Private Key and Public Key Pair Sample

DiffieHellman Private Key and Public Key Pair Sample

Dr. Herong Yang, updated in 2008
Private and Public Keys and Related Interfaces