Cryptography Tutorials - Herong's Tutorial Examples - v5.42, by Herong Yang
"openssl genrsa" Generating Private Key
This section provides a tutorial example on how to generate a RSA private key with the 'openssl genrsa' command. The key file can be then converted to DER or PEM encoding with or without DES encryption.
To understand better about PKCS#8 private key format, I started with "OpenSSL" to generate a RSA private key (it's really a private and public key pair). The "openssl genrsa" command can only store the key in the traditional format. But it offers various encryptions as options.
In the following test, I tried to use:
My command session was recorded as blow:
C:\herong>rem traditional format, PEM encoding, no encryption herong> openssl genrsa -out openssl_key.pem 1024 Loading 'screen' into random state - done Generating RSA private key, 1024 bit long modulus .......++++++ ........................................++++++ e is 65537 (0x10001) C:\herong>rem traditional format, DER encoding, no encryption herong> openssl rsa -in openssl_key.pem -inform pem \ -out openssl_key.der -outform der writing RSA key C:\herong>rem traditional format, PEM encoding, DES encryption herong> openssl rsa -in openssl_key.pem -inform pem \ -out openssl_key_des.pem -outform pem -des writing RSA key Enter PEM pass phrase: keypass Verifying - Enter PEM pass phrase: keypass C:\herong>rem traditional format, DER encoding, DES encryption herong> openssl rsa -in openssl_key.pem -inform pem \ -out openssl_key_des.der -outform der -des writing RSA key
All commands were executed as expected except the last one. The traditional format with DER encoding seems not able to apply the DES encryption.
Anyway, I got my RSA private key stored in OpenSSL traditional format with 3 flavors:
608 openssl_key.der 887 openssl_key.pem 958 openssl_key_des.pem
Now I am ready to my private key to PKCS#8 format as described in the next section.
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
Certificate X.509 Standard and DER/PEM Formats
►Migrating Keys from "OpenSSL" Key Files to "keystore"
►"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"