title: will java messagedigest generated different MD5 hash on different jdk version?
body: <p>I am using java message digest to create MD5 hash, which is used for authentication. The MD5 hash is stored in the database as varchar2. I did a test to create a user on my tomcat server on my local laptop. When I deployed the war to the test tomcat server on linux redhat, the authentication failed due to hash unmatched. I checked the user name and password: they are all correct. Both web server points to the same database.</p>
  
  <p>I suspect the hash generated on my local laptop is different from the one generated by the test server. Am I right?  </p>
  
  <p>Below is the code with which I generated the hash. </p>
  
  <pre><code>public static String getMD5Hash(String str) throws Exception
  {
      MessageDigest md = MessageDigest.getInstance("MD5");
  
      md.update(str.getBytes());
      return new String(md.digest());
  }
  </code></pre>
  
  <p>The String returned will be saved in the database table, which is defined below</p>
  
  <pre><code>create table authen(
     passport varchar2(50),
     constraint pk_au primary key (passport) USING INDEX TABLESPACE xxxxxxx
  );
  </code></pre>
  
  <p>Here is the java version output on my laptop</p>
  
  <pre><code>C:\Users\XXXX&gt;java -version
  java version "1.6.0_25"
  Java(TM) SE Runtime Environment (build 1.6.0_25-b06)
  Java HotSpot(TM) Client VM (build 20.0-b11, mixed mode, sharing)
  </code></pre>
  
  <p>Here is the java version output on the redhat server</p>
  
  <pre><code>[xxxxxx@xxxxxxxxx ~]$ java -version
  java version "1.6.0_20"
  Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
  Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode, sharing)
  </code></pre>