RSA Private Key and Public Key Pair Sample

This section provides a tutorial example on how to run JcaKeyPair.java to generate a RSA private key and public key pair sample. Keys are stored PKCS#8 and X.509 encoding formats.

Now let's see the private key and public key generated by the RSA algorithm:

>java -cp . JcaKeyPair 512 rsa rsa

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

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

Public Key Info:
Algorithm = RSA
Saved File = rsa.pub
Size = 94
Format = X.509
toString = Sun RSA public key, 512 bits
  modulus: 
     8501360768135846209281243379820297263815731275954336277423435334
     0634158627863282350694681262665444471208937440958312181724505235
     80919843567632096247396963
  public exponent: 65537

>java -cp . HexWriter rsa.pri rsa_pri.hex

>type rsa_pri.hex
30820154020100300D06092A864886F7
0D01010105000482013E3082013A0201
00024100A251C92CCA3E7B6599146DDB
10044807B3AA1EFA8BE6274D329765E0
CC5A0EA03CA8F010524A892484A7C964
98660A20DBD3AA3E92D2CB5037DD95B7
F69BBA630203010001024040603F714C
24CBBBD7A28A8F3F22F38E5A6B362E18
1E07A84E504D4F82BC94DFC402775FF0
7428E97620750BF965E5E960B5B6FFEB
64A62813B8AAFF1A6B5101022100F2D0
13B5A010AAE6C77D3993F7A5C1ED7DB4
F2BECC8383E6943620628B8680910221
00AB2293FF88A958F22F7A087BA00605
64135A9A4A4014538013B0ED1A1CBD05
B3022100D50474F61739E824D48868B6
064216331AE05F41C23BF2C09BF02C53
27E2D4F1022051C44EB44C46A5B1E98F
441855482B313AB212802187D4B1A036
EBC28B32A15302205D1A78497DC3E337
7224BBAF3F50791F2CEC932B04DD28AD
3763F6E233DBA634

>java -cp . HexWriter rsa.pub rsa_pub.hex

>type rsa_pub.hex
305C300D06092A864886F70D01010105
00034B003048024100A251C92CCA3E7B
6599146DDB10044807B3AA1EFA8BE627
4D329765E0CC5A0EA03CA8F010524A89
2484A7C96498660A20DBD3AA3E92D2CB
5037DD95B7F69BBA630203010001

Last update: 2014.

Table of Contents

 About This JDK Tutorial Book

 Downloading and Installing JDK 1.8.0 on Windows

 Downloading and Installing JDK 1.7.0 on Windows

 Downloading and Installing JDK 1.6.2 on Windows

 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

 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

 Private and Public Keys and Related Interfaces

 KeyPair and KeyPairGenerator Classes

 Key Pair Sample Program - JcaKeyPair.java

 DSA Private Key and Public Key Pair Sample

RSA Private Key and Public Key Pair Sample

 DiffieHellman Private Key and Public Key Pair Sample

 PKCS#8/X.509 Private/Public Encoding Standards

 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)

 Outdated Tutorials

 References

 PDF Printing Version