Cryptography Tutorials - Herong's Tutorial Examples - v5.42, by 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:
herong> 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 herong> 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".
Table of Contents
Introduction to AES (Advanced Encryption Standard)
DES Algorithm - Illustrated with Java Programs
DES Algorithm Java Implementation
DES Algorithm - Java Implementation in JDK JCE
DES Encryption Operation Modes
PHP Implementation of DES - mcrypt
Blowfish - 8-Byte Block Cipher
Secret Key Generation and Management
Cipher - Secret Key Encryption and Decryption
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
OpenSSL Introduction and Installation
OpenSSL Generating and Managing RSA Keys
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"