Cryptography Tutorials - Herong's Tutorial Examples - Version 5.21, by Dr. Herong Yang

"keytool -list" Verifying PKCS#12 Files

This section provides a tutorial example on how to merge a private key and its self-signed certificate into a single PKCS#12 file, with can be then encoded as PEM and encrypted with DES.

Since Java SE "keytool" command support PKCS#12 files, I want to try it with my PKCS#12 file, openssl_key_crt.p12, created by "OpenSSL" with the following tests:

  • Use "keytool -list" command to display what's in the PKCS#12 file.
  • "keytool -exportcert" command only exports the self-signed certificate from a PrivateKeyEntry in a keystore.

My command session was recorded as blow:

>keytool -list -keystore openssl_key_crt.p12 -storetype pkcs12 
-storepass p12pass

Keystore type: PKCS12
Keystore provider: SunJSSE

Your keystore contains 1 entry

openssl_key_crt, Jul 29, 2007, PrivateKeyEntry,
Certificate fingerprint (MD5): 1D:D4:AC:96:53:25:9F:1A:D0:A7:46:6C...

>keytool -exportcert -keystore openssl_key_crt.p12 -storetype pkcs12 
-storepass p12pass -alias openssl_key_crt 
-file keytool_openssl_crt.pem -rfc

Certificate stored in file <keytool_openssl_crt.pem>

Notes on the commands and options I used:

  • "keytool -list" command lists what's in the keystore file.
  • "-keystore openssl_key_crt.p12" option specifies the keystore file, a PKCS#12 file generated by "OpenSSL".
  • "-storetype pkcs12" option specifies the type of the keystore file, "jks" or "pkcs12".
  • "-storepass p12pass" option specifies the password to open the keystore file.
  • "keytool -exportcert" command exports the self-signed certificate out of the keystore file.
  • "-rfc" option tells keytool to write the certificate file with PEM (RFC1421) encoding.

The tests were successful and helped me to learn that:

  • The PKCS#12 file generated by "OpenSSL" does meet the PKCS#12 standard.
  • "OpenSSL" and "keytool" can share keystore files in PKCS#12 format.

As an exercise, you can open "openssl_crt.pem" and "keytool_openssl_crt.pem". They should contain the same Base64 encoded strings.

In the next section, I want to try to convert the PKCS#12 file to a JKS (Java KeyStore) file.

Last update: 2013.

Table of Contents

 About This Book

 Cryptography Terminology

 Cryptography Basic Concepts

 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

 Certificate X.509 Standard and DER/PEM Formats

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

 What Is PKCS#8?

 What Is PKCS#12?

 "openssl genrsa" Generating Private Key

 "openssl pkcs8" Converting Keys to PKCS#8 Format

 "openssl pkcs12" Merging Key with Certificate

"keytool -list" Verifying PKCS#12 Files

 "keytool -importkeystore" Importing PKCS#12 Files

 Summary - Migrating "OpenSSL" Keys to "keystore"

 Summary - Migrating "keystore" Keys to "OpenSSL"

 Using Certificates in IE (Internet Explorer)

 Using Certificates in Firefox

 Using Certificates in Google Chrome

 Outdated Tutorials

 References

 Printable Copy - PDF Version

"keytool -list" Verifying PKCS#12 Files - Updated in 2014, by Dr. Herong Yang