Question: What do you have to do ? You are given a number of files to use as outlined below: - PublicKeyEncryption.java: This is a complete

What do you have to do?
You are given a number of files to use as outlined below:
- PublicKeyEncryption.java: This is a complete class that you cannot modify. It contains the
basics to use Asymmetric Key Encryption.
- SimpleAsymKeyEncryptApp.java: This is *mostly* a complete class. You will need to add
code and modify existing code as outlined below in steps 1-11.
- MasterPrivateKey.key: This is a private key that was generated along with its public key
equivalent. The public key was used to encrypted the next file...
- Encrypted.bin: This file contains encrypted text. The key in the file MasterPrivateKey.key
will decrypt it.
Changed you need to implement:
1. Convert the for loop in private static String getTextFileAsString() method to a while loop. Make
sure to comment the method as well.
2. Surround the long if/else structure in main method with a do/while loop, such that the program
will only end when the user enters in the value 8 as a choice.
3. Convert the long if/else structure to a switch/case. Also take care of the scenario where the user
does not enter a valid choice (1-8). Tell them they made an invalid choice. Hint: look up the
default keyword.
4. For choices 1 through 7... slightly modify the code to allow the user to choose the names of the
files (instead of them being hardcoded). Hint, use an instance of Scanner to get the users
response, and store their answer in a String.
5. Change choice 7 so the decrypted text is written to a text file (of the users choice) instead of
the console (Hint: replace System.out with an instance of PrintWriter... dont forget to close it
either!)
6. Test the program. Create a text file (either with notepad or Eclipse) and put a message in it (less
than 117 characters). Run the program, choose 4 and encrypt the text file.
Immediately choose 5. See if the decrypted text file matches the original text files message.
7. Choose options 1 and 2 to save the current pair of public and private keys to text files.
8. Choose 8 to quit.
9. Rerun the program.
10. Use the private key provided to you MasterPrivateKey.key on myCourses with choice 7. Use the
file Encrypted.bin from myCourses as the encrypted file to decrypt here. The resulting file, if all
works properly, will contain a message in English.
11. Rerun the program again a few times, choosing option 4 to encrypt a new text file with varying
amounts of text. Be sure to save the encrypted files with different names.
12. Answer the following questions in the comments at the top of your code
(SimpleAsymKeyEncryptApp.java)
a. For each of the encrypted files you created, what can you note about the file size? (right
click on the file and choose properties).
b. Does it seem like the amount of text you encrypted seemed to have an impact on the
encrypted files size?
c. Does the size seem to relate to the limitation of the number of characters in the textfile
(117)?
d. If we cant go above 117 characters to encrypt, but we have more than 117 to encrypt,
what would be a simple solution to fix this? (Hint: If you have to ship a large item, but
that item is bigger than the biggest single box allowed to ship it, what can you do to the
item to ship it and make sure it all makes it there in the end?)
13. Done? Demonstrate the program to the TA. Be sure to show the decrypted message from step
10 as well.
14. Submit the following files to myCourses.
a. PublicKeyEncryption.java
b. SimpleAsymKeyEncryption.java
c. The text file you created with some message in step 6.
d. The encrypted file created by the program in step 6.
e. The private key file from step 7.
f. The public key file from step 7. import java.util.*;
import java.io.*;
import java.security.*;
public class SimpleAsymKeyEncryptApp {
public static void main(String[] args){
//Other implementations other than RSA do not work without messing with Eclipse's settings
PublicKeyEncryption pke1= new PublicKeyEncryption(PublicKeyEncryption.AlgorithmTypes.RSA);
//Keyboard input.
Scanner kbInput = new Scanner(System.in);
//Used to get the users choice from the
int choice;
String bufferData;
byte encryptedData[], decryptedData[];
PublicKey publicK;
PrivateKey privateK;
System.out.println("=======================================================");
System.out.println("Welcome to the Simple Asymmetric Key Encryption Program");
System.out.println("=======================================================");
System.out.println("Please choose from the following options:");
System.out.println("1. Save my public key to a binary file.");
System.out.println("2. Save my private key to a binary file.");
System.out.println("3. Generate a new set of my keys.");
System.out.println("4. Encrypt using my key");
System.out.println("5. Decrypt using my key");
System.out.println("6. Encrypt using a key from a file");
System.out.println("7. Decrypt using a key from a file");
System.out.println("8. Quit the program

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!