Finding Large Prime Numbers

This section describes different ways to generate large prime numbers to be used to generate public key and private key. Today most RSA tools are using probable prime numbers.

Now we have an efficient algorithm for the RSA encryption and decryption operation, the next thing to look at is on how to generate public and private keys.

The first step of the public and private key generation process is to get 2 large prime numbers. This can be done in different ways:

1. Selecting existing prime numbers from prime number databases. If you need 2 prime numbers to generate a new pair public key and private key, you can select 2 prime numbers from an existing prime number database like, which currently have about 1.4 billion prime numbers.

The largest prime number currently stored in is 32416190071, which has 11 decimal digits. If select 2 11-digit prime numbers, p and q, the product of p and q, n, will be have 22 decimal digits, which is about 50-bit long. This tells us that if we use prime numbers from, we can only generate 50-bit RSA keys.

This is not long enough to meet today's security standard. Remember, security experts recommend to use 2048-bit public and private keys if you want to keep your data safe up to year 2030.

2. Generating prime numbers using prime number generating algorithms. If you need 2 prime numbers to generate a new pair public key and private key, you can generate 2 prime numbers using a prime number generating algorithm like "Sieve of Eratosthenes" which iteratively marking composite (i.e. not prime) by calculating multiples of each known prime and keeping numbers that are not marked as prime numbers at the end.

The "Sieve of Eratosthenes" algorithm is very efficient algorithm to generate prime numbers. But it is still takes too long to generate large prime numbers.

3. Generating probable prime numbers using probable prime number generating algorithms. If you need 2 prime numbers to generate a new pair public key and private key and don't want to wait for a long time to find them, you can generate 2 probable prime numbers using a probable prime number generating algorithm like the probablePrime() method provided in java.math.BigInteger class.

Of course, public key and private key generated from probable prime numbers may fail to work in encryption and description. But the likelihood of failure is very small.

Today most RSA public key and private key tools are using probable prime numbers.

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

 What Is Public Key Encryption?

 RSA Public Key Encryption Algorithm

 Illustration of RSA Algorithm: p,q=5,7

 Illustration of RSA Algorithm: p,q=7,19

 Proof of RSA Public Key Encryption

 How Secure Is RSA Algorithm?

 How to Calculate "M**e mod n"

 Efficient RSA Encryption and Decryption Operations

 Proof of RSA Encryption Operation Algorithm

Finding Large Prime Numbers

 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

 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


 PDF Printing Version