Question: The Crypto.java encrypts the data. FileEncryptionFilter.java demonstrates a solution using Crypto class to make an encrypted copy of the file MyLetters.txt. The encrypted copy is

The Crypto.java encrypts the data. FileEncryptionFilter.java demonstrates a solution using Crypto class to make an encrypted copy of the file "MyLetters.txt". The encrypted copy is stored in "Encrypted.txt". Crypto.java is incomplete. Please complete Crypto.java to fulfill the encryption function. You need to use Exception Handling and proper File I/O operation in your Crypto.java.

Crypto.java:

public class Crypto

{

/**

The encryptFile method makes an encrypted copy

of an existing file.

@param existing The name of the existing file to encrypt.

@param encrypted The name of the encrypted file to create.

@exception IOException When an IO error occurs.

*/

public static void encryptFile(String existing, String encrypted)

throws IOException

{

boolean eof = false; // End of file flag

// Open the files.

FileInputStream inStream = new FileInputStream(existing);

DataInputStream inFile = new DataInputStream(inStream);

FileOutputStream outStream = new FileOutputStream(encrypted);

DataOutputStream outFile = new DataOutputStream(outStream);

// Process the file. TIP: use readByte:

//byte input = inFile.readByte();

while (!eof)

{

}

//close the files

}

}

FileEncryptionFilter.java

public class FileEncryptionFilter { public static void main(String[] args) { System.out.println("Encrypting the contents of the file"); System.out.println("MyLetters.txt. The encrypted file will"); System.out.println("be stored as Encrypted.txt");

try { Crypto.encryptFile("MyLetters.txt", "Encrypted.txt"); System.out.println("Done. Use Notepad to inspect the encrypted file."); } catch (IOException e) { System.out.println("Error - " + e.getMessage()); } } }

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!