Cryptography Tutorials - Herong's Tutorial Examples - Version 5.36, by Dr. Herong Yang
"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