title: Java self-checking program (self-checksuming)
body: <p>I have to do a little java self-checking programm (self-checksum). 
  here my code sample</p>
  
  <pre><code>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");
        }
  }
  </code></pre>
  
  <p>I have tried to do something like that</p>
  
  <pre><code>DigestInputStream sha = new DigestInputStream(fr, MessageDigest.getInstance("SHA"));
  byte[] digest = sha.getMessageDigest();
  
  for(..)
  {
  result = result + digest[i]
  }
  </code></pre>
  
  <p>But then i don't really know how to check that ??</p>
  
  <p>EDIT:</p>
  
  <p>Thanks for your answers</p>
  
  <p>@ Adam Paynter and SpoonBenders</p>
  
  <p>Naturally this is not for my personal use. And I wont use that to protect any software.....</p>
  
  <p>It's an "exercice" i have to do for my java course...</p>