Hi,
I have to do a little java self-checking programm (self-checksum). here my code sample
public class tamper {
public static int checksum_self () throws Exception {
File file = new File ("tamper.class");
FileInputStream fr = new FileInputStream (file);
int result; // Compute the checksum
return result;
}
public static boolean check1_for_tampering () throws Exception {
return checksum_self () != 0; // TO BE UPDATED!
}
public static int check2_for_tampering () throws Exception {
return checksum_self ();
}
public static void main (String args[]) throws Exception {
if (check1_for_tampering ()) {
System.exit (-1);
}
float celsius = Integer.parseInt (args[0]);
float fahrenheit = 9 * celsius / 5 + 32;
System.out.println (celsius + "C = " + fahrenheit + "F");
}
}
I have tried to do something like that
DigestInputStream sha = new DigestInputStream(fr, MessageDigest.getInstance("SHA"));
byte[] digest = sha.getMessageDigest();
for(..)
{
result = result + digest[i]
}
But then i don't really know how to check that ??
Your help will be really apreciate!
Thanks

New Topic/Question
Reply
MultiQuote






|