java.lang.ObjectRSA
public class RSA
| 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 |
|---|
private final BigInteger d
private final BigInteger e
private final BigInteger n
private static final Random rnd
| Constructor Detail |
|---|
public RSA(int numBits)
numBits - The number of bits in the modulus and exponents.
public RSA(String keyFile)
throws FileNotFoundException,
IOException
keyFile - The name of a file containing a modulus and exponent.
FileNotFoundException
IOException| Method Detail |
|---|
public void decrypt()
throws IOException
decrypt in interface AbstractRSAIOException
public void encrypt()
throws IOException
encrypt in interface AbstractRSAIOException
public static void main(String[] arguments)
throws IOException
Encrypts or decrypts by command-line arguments using an RSA cryptosystem.
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
numBitsto 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.
IOException - if an I/O error occurs.public void printKeys()
printKeys in interface AbstractRSAprivate static BigInteger randomRelativePrime(BigInteger m)
m - The modulus to which a random relative prime is returned.