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.5
Key Size = 512
toString = java.security.KeyPairGenerator$Delegate@a59698

Private Key Info:
Algorithm = RSA
Saved File = rsa.pri
Size = 346
Format = PKCS#8
toString = Sun RSA private CRT key, 512 bits
  modulus:          90869450415146058688797477200948425302945076773547
1740987359289561440861968860814477403774349719761641670312566894138086
6493349088794356554895149433555027
  public exponent:  65537
  private exponent: 89365058183270423953039885874475912959479623544084
4479456143566699940284657762576258282420226939967257905899144258740638
4754958587400493169361356902030209
  prime p:          10156561001330124071320723955895014468217435540658
9305284428666903702505233009
  prime q:          89468719188754548893545560595594841381237600305314
352142924213312069293984003
  prime exponent p: 93508487983621011980308809077436163233486980736420
426663592427234014400426465
  prime exponent q: 39924206061844862938366722914051164017185614552526
332124140845908593107749243
  crt coefficient:  82979745043413288095388081210478420482729140505221
184605143714377105157807297

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

java -cp . HexWriter rsa.pri rsa_pri.hex

type rsa_pri.hex
30820156020100300D06092A864886F7
0D0101010500048201403082013C0201
00024100AD800FE8B7445E8B1C84527E
02899F585CFFDB3548C36EBC29FCE7AC
3E44CCC421FACBAA98475FB4764E8F3D
3EE8C1BEFB554882E6AD9ABC8404F4A4
F0E308530203010001024100AAA0BB04
9ED7BA330D4484EC300AB08EF2471D89
F5995D99E7A135260BC715A85E755563
1A89D80E55D91C898AF4DE5405A553A0
403249C4C610C503CD66DB81022100E0
8C191D98B8C1B20E6BD54E20CE60CB1E
712FB4E92DE0515BCDDEBF3CE79A7102
2100C5CD8023172DB0FE9DF0286C50BE
66312876C0869B69DBD9A847D1AC3E42
4903022100CEBBEDBBB40A163B0ACFF8
F90F7732E28F4A8233BBA3832D24AAAB
F3C1ED31E1022058444CC2DBEC02C88C
380801D5C2311E0C9D796A57DDD4427B
8A98F110D3497B022100B774DF0EF99B
53EF4B8E3B918604C0E362120BC11A2D
E8889E1872AB15965CC1

java -cp . HexWriter rsa.pub rsa_pub.hex

type rsa_pub.hex
305C300D06092A864886F70D01010105
00034B003048024100AD800FE8B7445E
8B1C84527E02899F585CFFDB3548C36E
BC29FCE7AC3E44CCC421FACBAA98475F
B4764E8F3D3EE8C1BEFB554882E6AD9A
BC8404F4A4F0E308530203010001

Comparing the default implementation of DSA algorithm with RSA algorithm, the DSA implementation returns all the internal parameters of the keys in the toString() method.

Last update: 2013.

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

 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

 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 (Internet Explorer)

 Using Certificates in Firefox

 Using Certificates in Google Chrome

 Outdated Tutorials

 References

 PDF Printing Version