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 -cp . JcaKeyFactoryTest 512 rsa RSA

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

Private Key Info:
Algorithm = RSA
Saved File = rsa.pri
Length = 344
Format = PKCS#8
toString = sun.security.rsa.RSAPrivateCrtKeyImpl@fffecc13

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

KeyFactory Object Info:
Algorithm = RSA
Provider = SunRsaSign version 10
toString = java.security.KeyFactory@ad8086

Private Key Info:
Algorithm = RSA
Saved File = rsa.pri
Length = 344
toString = sun.security.rsa.RSAPrivateCrtKeyImpl@fffecc13

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

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

Table of Contents

 About This JDK Tutorial Book

 JDK (Java Development Kit)

 Java Date-Time API

 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

 Java Logging

 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 - Encryption and Decryption

 The SSL (Secure Socket Layer) Protocol

 SSL Socket Communication Testing Programs

 SSL Client Authentication

 HTTPS (Hypertext Transfer Protocol Secure)

 Outdated Tutorials

 References

 Full Version in PDF/EPUB