"keytool -genkeypair" Generating PrivateKeyEntry

This section provides a tutorial example on how to generate a private and public key pair using the 'keytool -genkeypair' command. It stores the key pair in a 'PrivateKeyEntry' in a 'keystore' file.

To prepare my test on how to export private and public key pairs out of "keystore" files, I need to generate a pair of keys first in a "keystore" file with the "keytool -genkeypair" command. What I did was recorded below:

>java -version

java version "1.6.0_01"
Java(TM) SE Runtime Environment (build 1.6.0_01-b06)
Java HotSpot(TM) Client VM (build 1.6.0_01-b06, mixed mode,
  sharing)
  
>keytool -genkeypair -alias herong_key -keypass keypass
-keysize 1024 -keystore herong.jks -storepass jkspass

What is your first and last name?
  [Unknown]:  Herong Yang
What is the name of your organizational unit?
  [Unknown]:  Herong Unit
What is the name of your organization?
  [Unknown]:  Herong Company
What is the name of your City or Locality?
  [Unknown]:  Herong City
What is the name of your State or Province?
  [Unknown]:  Herong State
What is the two-letter country code for this unit?
  [Unknown]:  CA
Is CN=Herong Yang, OU=Herong Unit, O=Herong Company, 
L=Herong City, ST=Herong State, C=CA correct?
  [no]:  yes

>keytool -list -keystore herong.jks -storepass jkspass

Keystore type: JKS
Keystore provider: SUN

Your keystore contains 1 entry

herong_key, Apr 1, 2007, PrivateKeyEntry,
Certificate fingerprint (MD5): 0C:54:AE:99:4E:3D:F7:A9:7...

I am not going to explain all the command options used above, because they were explained in previous chapters. As you can see the private and public key pair is stored in a "PrivateKeyEntry".

In the next section, I tried to use "keytool -exportcert" to export this "PrivateKeyEntry".

Last update: 2013.

Table of Contents

 About This Book

 Cryptography Terminology

 Cryptography Basic Concepts

 Introduction to AES (Advanced Encryption Standard)

 Introduction to DES Algorithm

 DES Algorithm - Illustrated with Java Programs

 DES Algorithm Java Implementation

 DES Algorithm - Java Implementation in JDK JCE

 DES Encryption Operation Modes

 DES in Stream Cipher Modes

 PHP Implementation of DES - mcrypt

 Blowfish - 8-Byte Block Cipher

 Secret Key Generation and Management

 Cipher - Secret Key Encryption and Decryption

 Introduction of RSA Algorithm

 RSA Implementation using java.math.BigInteger Class

 Introduction of DSA (Digital Signature Algorithm)

 Java Default Implementation of DSA

 Private key and Public Key Pair Generation

 PKCS#8/X.509 Private/Public Encoding Standards

 Cipher - Public Key Encryption and Decryption

 MD5 Mesasge Digest Algorithm

 SHA1 Mesasge Digest Algorithm

 OpenSSL Introduction and Installation

 OpenSSL Generating and Managing RSA Keys

 OpenSSL Managing Certificates

 OpenSSL Generating and Signing CSR

 OpenSSL Validating Certificate Path

 "keytool" and "keystore" from JDK

 "OpenSSL" Signing CSR Generated by "keytool"

Migrating Keys from "keystore" to "OpenSSL" Key Files

 No "keytool" Command to Export Keys

"keytool -genkeypair" Generating PrivateKeyEntry

 "keytool -exportcert" Exporting PrivateKeyEntry

 "keytool -printcert" Printing Certificate Details

 "openssl x509" Viewing Certificate Details

 "DumpKey.java" Dumping Private Keys Out of "keystore"

 "openssl enc" Converting Keys from Binary to PEM

 "openssl dsa" Viewing Private and Public Key Pair

 Certificate X.509 Standard and DER/PEM Formats

 Migrating Keys from "OpenSSL" Key Files to "keystore"

 Using Certificates in IE (Internet Explorer)

 Using Certificates in Firefox

 Using Certificates in Google Chrome

 Outdated Tutorials

 References

 PDF Printing Version