The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > java.security.cert  [9 examples] > Certificates  [5 examples]

e223. Creating a New Key Pair and Self-Signed Certificate Using keytool

This example uses the keytool program to create a new key pair and self-signed certificate for the principal Duke. The example generates a 1024-bit Digital Signature Algorithm (DSA) key pair.
    > keytool -genkey -alias alias -keystore .keystore
    Enter keystore password: password
    What is your first and last name?
      [Unknown]: Duke
    What is the name of your organizational unit?
      [Unknown]: JavaSoft
    What is the name of your organization?
      [Unknown]: Sun
    What is the name of your City or Locality?
      [Unknown]: Cupertino
    What is the name of your State or Province?
      [Unknown]: CA
    What is the two-letter country code for this unit?
      [Unknown]: US
    Is <CN=Duke, OU=JavaSoft, O=Sun, L=Cupertino, ST=CA, C=US> correct?
      [no]: yes

To create a 1024-bit RSA key:
    > keytool -genkey -keyalg RSA -keysize 1024 -alias alias -keystore .keystore

 Related Examples
e224. Exporting a Certificate to a File
e225. Importing a Certificate from a File
e226. Listing All Available Certificate Formats
e227. Getting the Subject and Issuer Distinguished Names of an X509 Certificate

See also: Certification Paths   


© 2002 Addison-Wesley.