Class RSA
java.lang.Object
|
+--RSA
- public class RSA
- extends java.lang.Object
Program to encrypt and decrypt files using the RSA algorithm.
This program accepts arguments from the command line and can be run in 3
ways:
-
java RSA -mk [username] : create a pair of public and private key,
and a modulus for this username, and stores them in 3 files in
the local directory.
-
java RSA -e [username] [message_file] [encoded_file] : uses the
private key of username to crypt the file message_file.
The crypted message is stored in the file encoded_file.
-
java RSA -d [username] [encoded_file] [message_file] : uses the
public key of username to decrypt the file encoded_file.
The resulting clear file is stored in encoded_file.
RSA uses the functions implemented in class Math.
The keys are large prime of 1024 bits.
- Author:
- E.Lemonnier & E.Nordenstam
|
Constructor Summary |
RSA()
|
|
Method Summary |
static java.math.BigInteger |
decrypt(java.math.BigInteger cypher,
java.math.BigInteger key,
java.math.BigInteger modulus)
Decrypt a message with RSA. |
static java.math.BigInteger |
encrypt(java.math.BigInteger message,
java.math.BigInteger key,
java.math.BigInteger modulus)
Encrypt a message with RSA. |
static java.math.BigInteger[] |
keys()
Generate a pair of private and public keys, and a modulus. |
static void |
main(java.lang.String[] arg)
Crypt/Decrypt a file, or generate keys for a user.
|
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
SIZE_KEY
public static final int SIZE_KEY
RSA
public RSA()
main
public static void main(java.lang.String[] arg)
- Crypt/Decrypt a file, or generate keys for a user.
See on top of this page for a detailed description.
- Parameters:
see - the description above.
encrypt
public static java.math.BigInteger encrypt(java.math.BigInteger message,
java.math.BigInteger key,
java.math.BigInteger modulus)
- Encrypt a message with RSA. In fact compute
message ^ key mod modulus.
- Parameters:
message - the message to encrypt.key - the key used to crypt the message.modulus - key modulus.- Returns:
- the encoded message.
decrypt
public static java.math.BigInteger decrypt(java.math.BigInteger cypher,
java.math.BigInteger key,
java.math.BigInteger modulus)
- Decrypt a message with RSA. In fact compute
cypher ^ key mod modulus.
- Parameters:
cypher - the cypher to decrypt.key - the key used to crypt the message.modulus - key modulus.- Returns:
- the decrypted message.
keys
public static java.math.BigInteger[] keys()
- Generate a pair of private and public keys, and a modulus. The result
is an array of BigIntegers of this form:
[private_key, public_key, modulus].
- Returns:
- the 2 keys and the modulus.