"openssl pkcs8" Converting Keys to PKCS#8 Format

This section provides a tutorial example on how to convert a private key file from the traditional format into PKCS#8 format using the 'openssl pkcs8' command. Keys can still be encoded with DER or PEM with or without DES encryption in PKCS#8 format.

Once I have my private key stored in the traditional format, I can use the "openssl pkcs8" command to convert it into PKCS#8 format. My plan was to try to do the following:

My command session was recorded as blow:

C:\herong>rem PKCS#8 format, PEM encoding, no encryption
herong> openssl pkcs8 -topk8 -in openssl_key.pem -inform pem \
   -out openssl_key_pk8.pem -outform pem -nocrypt

C:\herong>rem PKCS#8 format, DER encoding, no encryption
herong> openssl pkcs8 -topk8 -in openssl_key.pem -inform pem \
   -out openssl_key_pk8.der -outform der -nocrypt

C:\herong>rem PKCS#8 format, PEM encoding, encrypted
herong> openssl pkcs8 -topk8 -in openssl_key.pem -inform pem \
   -out openssl_key_pk8_enc.pem -outform pem

Enter Encryption Password: keypass
Verifying - Enter Encryption Password: keypass
Loading 'screen' into random state - done

C:\herong>rem PKCS#8 format, DER encoding, encrypted
herong> openssl pkcs8 -topk8 -in openssl_key.pem -inform pem \
   -out openssl_key_pk8_enc.der -outform der

Enter Encryption Password: keypass
Verifying - Enter Encryption Password: keypass
Loading 'screen' into random state - done

All commands executed as expected this time. I got my RSA private key stored in OpenSSL traditional format and PKCS#8 format in 7 flavors:

   608 openssl_key.der
   887 openssl_key.pem
   958 openssl_key_des.pem
   634 openssl_key_pk8.der
   916 openssl_key_pk8.pem
   677 openssl_key_pk8_enc.der
   993 openssl_key_pk8_enc.pem

Now the question is how to verify them? Looks like there no easy tool to do this. I will leave this task later by writing a Java program to verify them.

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

 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

 Using Certificates in Google Chrome

 Using Certificates in Firefox

 Archived Tutorials

 References

 Full Version in PDF/EPUB