Reading RSA Private and Public Key Files

This section provides a tutorial example on running the test program JcaKeyFactoryTest.java to generate, write, read and convert RSA private and public keys.

Here is the result of my second test on JcaKeyFactoryTest.java for RSA private and public keys.

herong> java JcaKeyFactoryTest 512 rsa RSA

KeyPairGenerator Object Info: 
Algorithm = RSA
Provider = SunRsaSign version 12
Key Size = 512
toString = java.security.KeyPairGenerator$Delegate@a59698

Private Key Info: 
Algorithm = RSA
Saved File = rsa.pri
Length = 344
Format = PKCS#8
toString = Sun RSA private CRT key, 512 bits
  modulus:          97043338366949517069564373997756011362690918019854
3941758152851852995750181050015823269531963135480677112233564331161341
4599192233088071456509516387363439
  public exponent:  65537
  private exponent: 44482947462983207078242570750363738610961714271853
2410002848311984311844167238833772168785883650138424217232982825613734
1435787221995086138078350315762281
  prime p:          10113877693296832729678411411276047071299336819261
9571425067574407020218628277
  prime q:          95950674221883124976393580772166965334465293046924
608406056369328592349151507
  prime exponent p: 51357208257202083771147268467561159419224351131150
139882124964656472311148365
  prime exponent q: 74907613956824819663582421633995309739118089834030
405183140334167387871766905
  crt coefficient:  45674196662035780810780138565427379979561183703478
862392227968269998791179698

Public Key Info: 
Algorithm = RSA
Saved File = rsa.pub
Length = 94
Format = X.509
toString = Sun RSA public key, 512 bits
  modulus: 97043338366949517069564373997756011362690918019854394175815
2851852995750181050015823269531963135480677112233564331161341459919223
3088071456509516387363439
  public exponent: 65537

KeyFactory Object Info: 
Algorithm = RSA
Provider = SunRsaSign version 1.5
toString = java.security.KeyFactory@1e0cf70

Private Key Info: 
Algorithm = RSA
Saved File = rsa.pri
Length = 344
toString = Sun RSA private CRT key, 512 bits
  modulus:          97043338366949517069564373997756011362690918019854
3941758152851852995750181050015823269531963135480677112233564331161341
4599192233088071456509516387363439
  public exponent:  65537
  private exponent: 44482947462983207078242570750363738610961714271853
2410002848311984311844167238833772168785883650138424217232982825613734
1435787221995086138078350315762281
  prime p:          10113877693296832729678411411276047071299336819261
9571425067574407020218628277
  prime q:          95950674221883124976393580772166965334465293046924
608406056369328592349151507
  prime exponent p: 51357208257202083771147268467561159419224351131150
139882124964656472311148365
  prime exponent q: 74907613956824819663582421633995309739118089834030
405183140334167387871766905
  crt coefficient:  45674196662035780810780138565427379979561183703478
862392227968269998791179698

Public Key Info: 
Algorithm = RSA
Saved File = rsa.pub
Length = 94
toString = Sun RSA public key, 512 bits
  modulus:          97043338366949517069564373997756011362690918019854
3941758152851852995750181050015823269531963135480677112233564331161341
4599192233088071456509516387363439
  public exponent: 65537

The result confirms that my readKeys() method works perfectly.

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

 What Is Key Encoding?

 PKCS#8 and X.509 Key Encoding Classes

 java.security.KeyFactory - Reading Encoded Keys

 JcaKeyFactoryTest.java - Key Factory Test Program

 Reading DSA Private and Public Key Files

Reading RSA Private and Public Key Files

 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"

 Using Certificates in IE

 Using Certificates in Google Chrome

 Using Certificates in Firefox

 Archived Tutorials

 References

 Full Version in PDF/EPUB