Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Principles Of Multimedia Database Systems

Authors: V.S. Subrahmanian

1st Edition

1558604669, 978-1558604667

More Books

Students also viewed these Databases questions