java.Math.BigInteger Class

This section describes the standard Java class, java.Math.BigInteger, which offers a number of useful methods to help generating large probable prime numbers, generating public key and private key, encryption and decryption messages.

In order to help implementing RSA public key encryption algorithm, Java offers a standard class called java.Math.BigInteger that provides:

• BigInteger(int bitLength, int certainty, Random rnd) - Constructs a randomly generated positive big integer that is probably prime with the specified certainty and bit length. This constructor can be used to generate large probable prime numbers "p" and "q" to be used to generate RSA public key and private key.
• static BigInteger probablePrime(int bitLength, Random rnd) - Returns a randomly generated positive big integer that is probably prime with the default certainty and specified bit length. This method can be used to generate large probable prime numbers "p" and 'q" to be used to generate RSA public key and private key.
• public boolean isProbablePrime(int certainty) - Returns true if this bit integer is probably prime, false if it's definitely composite. This method can be used to validate large probable prime numbers "p" and "q" to be used to generate RSA public key and private key.
• public BigInteger gcd(BigInteger val) - Returns a bit integer whose value is the greatest common divisor of this big integer and the specified big integer. This method can be used to select "e" component in the public key such that "gcd(e,(p-1)*(q-a)) = 1".
• public BigInteger modInverse(BigInteger m) - Returns a big integer x such that x*(this big integer) mod m = 1. This method can be used to compute "d" component in the private key such that "d*e mod (p-1)*(q-a) = 1".
• public BigInteger modPow(BigInteger exponent, BigInteger m) - Returns a big integer whose value is (this big integer)**exponent mod m. This method can be used to compute the ciphertext (encryption) "C" using "M**e mod p*q", where "M" is the original message. It also can be used to compute the original message (decryption) "M" using "C**d mod p*q".

Last update: 2013.