Testing RsaKeyEncryption.java with a 3072-bit Key

This section provides a tutorial example on testing my RSA encryption and decryption implementation using the java.math.BigInteger class with a 3072-bit key.

In the last test, I want to try my RSA encryption and decryption implementation on a large key, 3072-bit key:

C:\herong>java RsaKeyGeneration 3072 > rsa_3072.key

C:\herong>type rsa_3072.key
p: 128081139829885235542800955228499173923808960750433007737693766...
q: 128081139829885235542800955228499173923808960750433007737693766...
m: 164047783801226141039199633638385807841290101177468164207580823...
Modulus: 164047783801226141039199633638385807841290101177468164207...
Key size: 3071
Public key: 115818800736950873270224324475859346802845181289027278...
Private key: 26148129677654121464582186764022283148199863115635111...

The first test uses the same hello.text file:

C:\herong>java RsaKeyEncryption rsa_3072.key 
   hello.text hello.encrypted

--- Reading public key ---
Modulus: 164047783801226141039199633638385807841290101177468164207...
Key size: 3071
Public key: 115818800736950873270224324475859346802845181289027278...
Cleartext block size: 256
Ciphertext block size: 384
Encryption block count: 1

C:\herong>java RsaKeyDecryption rsa_3072.key 
   hello.encrypted hello.decrypted

--- Reading private key ---
Modulus: 164047783801226141039199633638385807841290101177468164207...
Key size: 3071
Private key: 26148129677654121464582186764022283148199863115635111...
Cleartext block size: 256
Ciphertext block size: 384
Decryption block count: 1

C:\herong>type hello.decrypted
Hello world!

My RSA encryption and decryption implementation has no problem with large RSA keys. Now repeating the test on the same binary file:

C:\herong>java RsaKeyEncryption rsa_64.key 
   my_xcopy.exe my_xcopy_exe.encrypted

C:\herong>java RsaKeyEncryption rsa_3072.key 
   my_xcopy.exe my_xcopy_exe.encrypted

--- Reading public key ---
Modulus: 164047783801226141039199633638385807841290101177468164207...
Key size: 3071
Public key: 115818800736950873270224324475859346802845181289027278...
Cleartext block size: 256
Ciphertext block size: 384
Encryption block count: 145

C:\herong>java RsaKeyDecryption rsa_3072.key 
   my_xcopy_exe.encrypted my_xcopy_decrypted.exe

--- Reading private key ---
Modulus: 164047783801226141039199633638385807841290101177468164207...
Key size: 3071
Private key: 26148129677654121464582186764022283148199863115635111...
Cleartext block size: 256
Ciphertext block size: 384
Decryption block count: 145

C:\herong>comp my_xcopy.exe my_xcopy_decrypted.exe
Comparing my_xcopy.exe and my_xcopy_decrypted.exe...
Files compare OK

No problem. My RSA encryption and decryption implementation works with large RSA keys too. But the encryption took about 2 minutes to finish on my computer.

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

 java.Math.BigInteger Class

 Generating Prime Number with BigInteger Class

 Performance of Prime Number Generation

 RSA Encryption Implementation using BigInteger Class

 RsaKeyGenerator.java for RSA Key Generation

 RSA Keys Generated by RsaKeyGenerator.java

 RsaKeyValidator.java for RSA Key Validation

 64-bit RSA Key Validated by RsaKeyValidator.java

 Converting Byte Sequences to Positive Integers

 Cleartext Block Size for RSA Encryption

 Cleartext Message Padding and Revised Block Size

 Ciphertext Block Size for RSA Encryption

 RsaKeyEncryption.java for RSA Encryption Operation

 RsaKeyDecryption.java for RSA Decryption Operation

 Testing RsaKeyEncryption.java with a 16-bit Key

 Testing RsaKeyEncryption.java with a 64-bit Key

Testing RsaKeyEncryption.java with a 3072-bit Key

 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

 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