JDK (Java Development Kit) Tutorials
Dr. Herong Yang, Version 5.00

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. It is done with JDK 1.3.1.

java -cp . JcaKeyFactoryTest 512 rsa RSA

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

Private Key Info:
Algorithm = RSA
Saved File = rsa.pri
Length = 343
Format = PKCS8
toString = com.sun.rsajca.JSA_RSAPrivateKey@372a1a

Public Key Info:
Algorithm = RSA
Saved File = rsa.pub
Length = 94
Format = X509
toString = com.sun.rsajca.JSA_RSAPublicKey@12d342

KeyFactory Object Info:
Algorithm = RSA
Provider = SunRsaSign version 1.0
toString = java.security.KeyFactory@5ff48b

Private Key Info:
Algorithm = RSA
Saved File = rsa.pri
Length = 343
toString = com.sun.rsajca.JSA_RSAPrivateKey@fe7c3

Public Key Info:
Algorithm = RSA
Saved File = rsa.pub
Length = 94
toString = com.sun.rsajca.JSA_RSAPublicKey@3e2d65

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

Last update: 2006.

Table of Contents

 About This JDK Tutorial Book

 Downloading and Installing JDK 1.3.1 on Windows

 Downloading and Installing JDK 1.4.1 on Windows

 Downloading and Installing JDK 1.5.0 on Windows

 Downloading and Installing JDK 1.6.2 on Windows

 Date, Time and Calendar Classes

 Date and Time Object and String Conversion

 Number Object and Numeric String Conversion

 Locales, Localization Methods and Resource Bundles

 Calling and Importing Classes Defined in Unnamed Packages

 HashSet, Vector, HashMap and Collection Classes

 Character Set Encoding Classes and Methods

 Character Set Encoding Maps

 Encoding Conversion Programs for Encoded Text Files

 Socket Network Communication

 Datagram Network Communication

 DOM (Document Object Model) - API for XML Files

 SAX (Simple API for XML)

 DTD (Document Type Definition) - XML Validation

 XSD (XML Schema Definition) - XML Validation

 XSL (Extensible Stylesheet Language)

 Message Digest Algorithm Implementations in JDK

 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

 Digital Signature Algorithm and Sample Program

 "keytool" Commands and "keystore" Files

 KeyStore and Certificate Classes

 Secret Key Generation and Management

 Cipher - Secret Key Encryption and Decryption

 The SSL (Secure Socket Layer) Protocol

 SSL Socket Communication Testing Programs

 SSL Client Authentication

 HTTPS (Hypertext Transfer Protocol Secure)

 References

 PDF Printing Version

Dr. Herong Yang, updated in 2008
Reading RSA Private and Public Key Files