title: Checksum java class file
body: <p>I am writing a piece of software that needs licensing from government authority, there are more modules of the same kind (but doing different work - math algorithms). I need to secure that anytime anyone (mostly a representative of government authority) comes to this software and asks for it (via network), the checksum for that particular module is printed out. I am writing this server in Java. I looked into <code>Serialization</code> but it only cares about the data (attributes) in the object and not the object behaviour or other logical structure - which this absolutely needs to care about. Hence I need to access the <code>.class</code> from within the running jar file and perform a checksum on it. The current structure is like this:</p>
  
  <pre><code>abstract class Module {
      public abstract void run();
      public String chsum ();
  }
  
  abstract class SimpleGame extends Module {
      /* not that important */
  }
  
  class GameX extends SimpleGame {
      public void run() {
          /* some magic */
      }
  }
  </code></pre>
  
  <p>And when needed, upon receiving the proper message the network stack might call something like:</p>
  
  <pre><code>GameX gx = new GameX();
  String checkSum = gx.chsum();
  </code></pre>
  
  <p>My current progress got me nowhere, I tried to access the .class file but without any luck - it works only if it is not a jar archive. And I need to supply the <code>Class</code> instance which is not a dealbreaker but it sure is not that handy. If I could get an array of bytes containing the compiled <code>.class</code> file that would be more than enough - to perform a checksum on that is a piece of cake using <a href="http://java.sun.com/javase/6/docs/api/java/security/MessageDigest.html" rel="nofollow">MessageDigest</a></p>