hi, im trying to compare the md5 key of a file selected with the md5 key of known files stored in a text file. i can get the md5 key of the file selected and all & also read the text file line by line however, i cant seem to compare it properly. can someone check my codes and see if what im doing is right? or is there any way to compare that key with each line of the stored file.thanks :)
public void onAdd(Object newResource) {
if (newResource instanceof File) {
File file = (File) newResource;
if (file.isFile())
{
System.out.println(file.getAbsolutePath() + " is added");
try{
MessageDigest msgD=MessageDigest.getInstance("MD5");
FileInputStream fileStr = new FileInputStream((file.getAbsolutePath()));
byte[]dataBytes=new byte[1024];
int nread=0;
while((nread=fileStr.read(dataBytes))!=-1){
msgD.update(dataBytes,0,nread);
};
byte[]mdbytes=msgD.digest();
StringBuffer t = new StringBuffer();
for(int i=0;i<mdbytes.length;i++){
t.append(Integer.toString((mdbytes[i] & 0xff)+0x100,16).substring(1));
}
System.out.println("MD5 key stored : "+t.toString());
//scan both md5
try
{
FileReader input=new FileReader("test.txt");
BufferedReader bufRead=new BufferedReader(input);
String line;
int count=0;
line=bufRead.readLine();
count++;
if(bufRead.readLine().equals(t.toString()))
{
System.out.println("DENIED");
}
else
{
System.out.println("ALLOWED");
}
while(line!=null)
{
System.out.println(count+":"+line);
line=bufRead.readLine();
count++;
}
bufRead.close();
}catch(ArrayIndexOutOfBoundsException e)
{
e.printStackTrace();
}catch(IOException e)
{
e.printStackTrace();
}
//ends
}catch(Exception e)
{
}
}
}
}