Class RSA

java.lang.Object
  extended by RSA
All Implemented Interfaces:
AbstractRSA

public class RSA
extends Object
implements AbstractRSA


Field Summary
private  BigInteger d
          The exponent used to decrypt in this RSA cryptosystem.
private  BigInteger e
          The exponent used to encrypt in this RSA cryptosystem.
private  BigInteger n
          The modulus used to encrypt or decrypt in this RSA cryptosystem.
private static Random rnd
          An internal source of pseudo-randomness used by all instances.
 
Constructor Summary
RSA(int numBits)
          Constructs an RSA cryptosystem using a random modulus and exponents of specified bit length.
RSA(String keyFile)
          Constructs an RSA cryptosystem using a modulus and exponent read from a file.
 
Method Summary
 void decrypt()
          Decrypt the standard input stream using the modulus and exponent in this RSA cryptosystem.
 void encrypt()
          Encrypt the standard input stream using the modulus and exponent in this RSA cryptosystem.
static void main(String[] arguments)
          Encrypts or decrypts by command-line arguments using an RSA cryptosystem.
 void printKeys()
          Print the keys in this RSA cryptosystem to the standard output stream.
private static BigInteger randomRelativePrime(BigInteger m)
          Returns a random relative prime in the multiplicative group of units Zm*.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

d

private final BigInteger d
The exponent used to decrypt in this RSA cryptosystem.


e

private final BigInteger e
The exponent used to encrypt in this RSA cryptosystem.


n

private final BigInteger n
The modulus used to encrypt or decrypt in this RSA cryptosystem.


rnd

private static final Random rnd
An internal source of pseudo-randomness used by all instances.

Constructor Detail

RSA

public RSA(int numBits)
Constructs an RSA cryptosystem using a random modulus and exponents of specified bit length.

Parameters:
numBits - The number of bits in the modulus and exponents.

RSA

public RSA(String keyFile)
    throws FileNotFoundException,
           IOException
Constructs an RSA cryptosystem using a modulus and exponent read from a file.

Parameters:
keyFile - The name of a file containing a modulus and exponent.
Throws:
FileNotFoundException
IOException
Method Detail

decrypt

public void decrypt()
             throws IOException
Decrypt the standard input stream using the modulus and exponent in this RSA cryptosystem.

Specified by:
decrypt in interface AbstractRSA
Throws:
IOException

encrypt

public void encrypt()
             throws IOException
Encrypt the standard input stream using the modulus and exponent in this RSA cryptosystem.

Specified by:
encrypt in interface AbstractRSA
Throws:
IOException

main

public static void main(String[] arguments)
                 throws IOException

Encrypts or decrypts by command-line arguments using an RSA cryptosystem.

Parameters:
arguments - Command-line arguments controlling the cryptosystem.

The following arguments are meaningful, and have the following effects:

-g numBits
Print random keys of bit length numBits to the standard output stream.
-e keyFile
Encrypt the standard input stream using the modulus and exponent in the file named keyFile.
-d keyFile
Decrypt the standard input stream using the modulus and exponent in the file named keyFile.
Throws:
IOException - if an I/O error occurs.

printKeys

public void printKeys()
Print the keys in this RSA cryptosystem to the standard output stream.

Specified by:
printKeys in interface AbstractRSA

randomRelativePrime

private static BigInteger randomRelativePrime(BigInteger m)
Returns a random relative prime in the multiplicative group of units Zm*.

Parameters:
m - The modulus to which a random relative prime is returned.