Java の自己チェック プログラム (自己チェックサム) を少し実行する必要があります。ここに私のコードサンプル
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");
}
}
私はそのようなことをしようとしました
DigestInputStream sha = new DigestInputStream(fr, MessageDigest.getInstance("SHA"));
byte[] digest = sha.getMessageDigest();
for(..)
{
result = result + digest[i]
}
しかし、それを確認する方法が本当にわかりませんか??
編集:
回答ありがとうございます
@ Adam Paynter と SpoonBenders
当然、これは私的な使用のためではありません。そして、それを使用してソフトウェアを保護することはありません.....
これは、私のJavaコースのためにやらなければならない「演習」です...