First
assignment.
Due date: 09/13/05, at 9:00pm, via blackboard. (Use the dropbox feature
to drop the archive to the instructor).
Total points: 50.
After following the general
instructions to configure your home directory, and having installed
the BouncyCastle library:
Read the installation instructions for BouncyCastle at
http://www.bouncycastle.org/specifications.html#install.
It contains the following code snippet:
/*
* This will generate a random key, and encrypt the data
*/
Key
key;
KeyGenerator keyGen;
Cipher encrypt;
Security.addProvider(new BouncyCastleProvider());
try
{
// "BC" is the name of the BouncyCastle provider
keyGen = KeyGenerator.getInstance("DES", "BC");
keyGen.init(new SecureRandom());
key = keyGen.generateKey();
encrypt = Cipher.getInstance("DES/CBC/PKCS5Padding",
"BC");
}
catch (Exception e)
{
System.err.println(e);
System.exit(1);
}
encrypt.init(Cipher.ENCRYPT_MODE, key);
bOut = new ByteArrayOutputStream();
cOut = new CipherOutputStream(bOut, encrypt);
cOut.write("plaintext".getBytes());
cOut.close();
Your task is to extend the following snippet so that your file:
- Opens a file whose name is given as first argument in the command
line. Use the class DataInputStream to read chars
from the file, appending to a StringBuffer. Once you consumed all
the input from the file, you should get the String
accumulated in the StringBuffer. This will be encrypted in the
next step.
- Generate a random DES key, and use it to encrypt the String.
- Save the generated key and iv AS OBJECTS (you will need to use
the java.io.ObjectOutputStream class) in
a file whose name is given as second argument in the command line.
- Save the encrypted bytes (bOut.toByteArray()) using a
DataOutputStream to a third
file, whose name is given as the
third argument in the command line.
- Document your function using javadoc.
Create a package called assign1 to contain all the code you generate for this assignment.
(To do this create a subdirectory assign1 inside the src subdirectory, and
start each .java file with the header "package assign1;")
Return a single zip archive, containing your "src/assign1"
subdirectory.
IF YOU DON'T FOLLOW THE INPUT/OUTPUT SPECIFICATIONS ABOVE, YOUR MAXIMUM
GRADE IS
30% OF THE TOTAL NUMBER OF POINTS (ASSUMING THE PROGRAM HAS CORRECT
FUNCTIONALITY).
THIS IS AN INDIVIDUAL EFFORT. CODE WILL BE CHECKED FOR SIMILARITY
AND APPROPRIATE MEASURES
(SUCH AS GRADE REDUCTION AT THE LEAST) WILL BE TAKEN IF YOU ARE FOUND
DO VIOLATE STUDENT
ETHIC CODE OF CONDUCT.
Good Luck,
Breno.
Modified on 09/02/05 at 7:40pm.