Question: The first program should take two inputs as arguments: directory1 and directory2 . Your program should compute a hash value (using HMAC) for each file

The first program should take two inputs as arguments: directory1 and directory2 . Your program should compute a hash value (using HMAC) for each file (based on its content) in the folder directory1 and store that hash value in a new file that will be saved under the folder directory2. For example, if you have two files, file1 and file2, in directory1 , your program should create two files, say file1-hash and file2-hash that store the hash values of the contents of the corresponding two files under directory2.

********I have the first program done but the verification program that i have does not run which is the second program. the first program will be below *********

The second program should perform the verification process. It also takes two input arguments as the first program. It should generate hashes again (you can reuse some

code from the first program here) and check whether they are matching with the corresponding values stored in directory2 For each file, this program should output two strings: the filename and YES/NO (denoting whether the hashes are matching or not).

PROGRAM 1: Status is completed but need this for the second program.

import java.io.PrintWriter;

import java.security.MessageDigest;

public class Gen {

public static void main(String[] args)throws Exception

{

MessageDigest md = MessageDigest.getInstance("MD5");

md.update("/Users/FerrasNaser/Desktop/Directory1/essay.txt".getBytes());

byte byteData[] = md.digest();

StringBuffer sb = new StringBuffer();

for (int i = 0; i < byteData.length; i++) {

sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));

}

System.out.println("Hex format : " + sb.toString());

PrintWriter writer = new PrintWriter("/Users/FerrasNaser/Desktop/Directory2/essayhash1.txt", "UTF-8");

writer.println(sb);

writer.close();

}

}

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!