Previous | Next | Trail Map | Security in JDK 1.2  | Exchanging Files [Tools]

Generate Keys

In the previous step, you stored a contract file in a JAR file named Contract.jar. Before signing that JAR file, you need to generate keys, if you don't already have suitable keys available.

Whether you already have a keystore or not, you can create a new public/private key pair using the keytool -genkey command; if the specified keystore doesn't yet exist, it will be created.

Pretend you are Stan Smith and you work in the legal department of "XYZ" corporation. To create a new keystore named stanstore and generate keys, do the following. In your command window, type:

    keytool -genkey -alias signLegal -keystore stanstore

You will be prompted for the keystore password, your "distinguished name" information, and the key password. Below are shown the prompts, along with what you should type (which is indicated in bold):

    Enter keystore password:  balloon53 
    What is your first and last name?
      [Unknown]:  Stan Smith 
    What is the name of your organizational unit?
      [Unknown]:  Legal 
    What is the name of your organization?
      [Unknown]:  XYZ 
    What is the name of your City or Locality?
      [Unknown]:  New York
    What is the name of your State or Province?
      [Unknown]:  NY 
    What is the two-letter country code for this unit?
      [Unknown]:  US 
    Is  correct?
      [no]:  y 
    
    Enter key password for 
            (RETURN if same as keystore password):  cat876 

The above keytool command creates the keystore named "stanstore " in the same directory in which the command is executed (assuming the specified keystore doesn't already exist), and assigns it the password "balloon53". It generates a public/private key pair for the entity whose "distinguished name" has a common name of "Stan Smith", organizational unit of "Legal", etc.

It creates a self-signed certificate that includes the public key and the distinguished name information. This certificate will be valid for 90 days, which is the default validity period if you don't specify a -validity option. The certificate is associated with the private key in a keystore entry referred to by the alias "signLegal". The private key is assigned the password "cat876".


Previous | Next | Trail Map | Security in JDK 1.2  | Exchanging Files [Tools]