Different results with MessageDigest on different machines
843810Sep 5 2002 — edited May 27 2004Hi all, please can somebody give advice on this...
I get different results from hashing a password using the same code, but on different machines:
Machine 1: Windows 2000, US English version, java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode))
password: P/vNwCWGJvy4ofo0WKW9Kw==
Machine 2: Windows 2000 Korean version, java version "1.4.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_01-b03)
Java HotSpot(TM) Client VM (build 1.4.0_01-b03, mixed mode)
password: P/vNPz/8uKH6NFg/Kw==
Please note the different results of the hashed password.
Here is the code I use:
MessageDigest sha = null;
try {
sha = MessageDigest.getInstance("MD5");
}
catch (NoSuchAlgorithmException e) {
LoggingManager.error(this, "Exception: ", e);
}
byte[] tmp = password.getBytes();
sha.update(tmp);
com.sun.net.ssl.internal.www.protocol.https.BASE64Encoder b64Enc = new com.sun.net.ssl.internal.www.protocol.https.BASE64Encoder();
String md5enc = new String(sha.digest());
String encodedPassword = b64Enc.encodeBuffer(md5enc.getBytes());
Whats the reason for the different results and how can I overcome this problem`
Thanks for your help in advance!
Bernd