The first program should take two inputs as arguments: directory1 and directory2. the program should compute a hash value (using HMAC) for each file in the folder directory1 and store that hash value in a new file that will be saved under the folder directory2. (b). The second program should perform the verification process. It also takes the same 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 matched or not)
i have done some work which will generate hash value of a single file from one folder and i need help in generating hash value of all files from that folder these are the codes as follows.
Function
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.security.MessageDigest;
public class HMAC {
public static void main(String args[]) throws Exception {
String datafile = "/Users/Samip/Desktop/crypto1";
MessageDigest md = MessageDigest.getInstance("SHA1");
FileInputStream fis = new FileInputStream(datafile);
byte[] dataBytes = new byte[1024];
int nread = 0;
while ((nread = fis.read(dataBytes)) != -1) {
md.update(dataBytes, 0, nread);
};
byte[] mdbytes = md.digest();
//convert the byte to hex format
StringBuffer sb = new StringBuffer("");
for (int i = 0; i < mdbytes.length; i++) {
sb.append(Integer.toString((mdbytes[i] & 0xff) + 0x100, 16).substring(1));
}
//System.out.println("SHA-1 value is :: " + sb.toString());
FileWriter file = new FileWriter("/Users/Samip/Desktop/crypto/output.txt");
PrintWriter output = new PrintWriter(file);
output.println(sb.toString());
output.close();
System.out.println(sb.toString());
}
}
i hope someone can help me with this.