Will java messagedigest generate different MD5 hashes on different versions of jdk?

I am using java message digest to create an MD5 hash that 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 launched the war on the tomcat test server on linux redhat, authentication failed due to the lack of a hash. I checked the username and password: they are all correct. Both web servers point to the same database.

I suspect that the hash created on my local laptop is different from the hash created by the test server. I'm right?

Below is the code with which I created the hash.

public static String getMD5Hash(String str) throws Exception { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(str.getBytes()); return new String(md.digest()); } 

The returned row will be stored in the database table, which is defined below

 create table authen( passport varchar2(50), constraint pk_au primary key (passport) USING INDEX TABLESPACE xxxxxxx ); 

Here is the java version output on my laptop

 C:\Users\XXXX>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) 

Here is the Java version on redhat server

 [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) 
+8
java md5
source share
3 answers

Perhaps you are using the default character set to generate the bytes that you pass to the MD5.digest() method, and this character set is different between your laptop and server.

This may be the reason that you see different results. Otherwise, it cannot generate different results.

For example -

 byte[] bytesOfMessage = tempStr.getBytes("UTF-8"); // Maybe you're not using a charset here MessageDigest md5 = MessageDigest.getInstance("MD5"); byte[] theDigest = md5.digest(bytesOfMessage); 
+6
source share

Only if you submit different data to the MD5 digest. One way to do this by accident is to pass the hashCode values.

There is only one MD5 algorithm, and it will reproduce the same result everywhere on the same input.

+3
source share

Check if your hash is salted. Soloing means that the password is connected to another line to increase the security of hashing (to cancel the effect of rainbow tables).

It is possible that your database hashes are salty: hence the difference between your (unsalted or incorrect salty) MD5 hashes.

Each entry in the MD5 algorithm results in the same hash. This is the point of any hashing algorithm.

0
source share

All Articles