diff --git a/src/main/java/helma/framework/ResponseTrans.java b/src/main/java/helma/framework/ResponseTrans.java index 77ce2869..6be7a2f3 100644 --- a/src/main/java/helma/framework/ResponseTrans.java +++ b/src/main/java/helma/framework/ResponseTrans.java @@ -865,7 +865,7 @@ public final class ResponseTrans extends Writer implements Serializable { if (what == null) { digest.update(new byte[0]); } else if (what instanceof Date) { - digest.update(MD5Encoder.toBytes(((Date) what).getTime())); + digest.update(Long.toBinaryString(((Date) what).getTime()).getBytes()); } else if (what instanceof byte[]) { digest.update((byte[]) what); } else { @@ -889,7 +889,7 @@ public final class ResponseTrans extends Writer implements Serializable { // add the application checksum as dependency to make ETag // generation sensitive to changes in the app - byte[] b = digest.digest(MD5Encoder.toBytes(app.getChecksum())); + byte[] b = digest.digest(Long.toBinaryString((this.app.getChecksum())).getBytes()); setETag(new String(Base64.encodeBase64(b))); } diff --git a/src/main/java/helma/util/CryptFile.java b/src/main/java/helma/util/CryptFile.java index bc44c679..0f3c7470 100644 --- a/src/main/java/helma/util/CryptFile.java +++ b/src/main/java/helma/util/CryptFile.java @@ -19,6 +19,8 @@ package helma.util; import java.io.*; import java.util.*; +import org.apache.commons.codec.digest.DigestUtils; + /** * This file authenticates against a passwd file */ @@ -68,7 +70,7 @@ public class CryptFile { } // then try MD5 - if (realpw.equals(MD5Encoder.encode(pw))) { + if (realpw.equals(DigestUtils.md5(pw))) { return true; } } catch (Exception x) { diff --git a/src/main/java/helma/util/CryptResource.java b/src/main/java/helma/util/CryptResource.java index 617b6662..7a7d5ab4 100644 --- a/src/main/java/helma/util/CryptResource.java +++ b/src/main/java/helma/util/CryptResource.java @@ -20,6 +20,9 @@ import java.io.BufferedReader; import java.io.StringReader; import java.util.Properties; import java.util.StringTokenizer; + +import org.apache.commons.codec.digest.DigestUtils; + import helma.framework.repository.Resource; import helma.framework.repository.Resource; @@ -73,7 +76,7 @@ public class CryptResource { } // then try MD5 - if (realpw.equals(MD5Encoder.encode(pw))) { + if (realpw.equals(DigestUtils.md5(pw))) { return true; } } catch (Exception x) { diff --git a/src/main/java/helma/util/MD5Encoder.java b/src/main/java/helma/util/MD5Encoder.java deleted file mode 100644 index ee4e5a96..00000000 --- a/src/main/java/helma/util/MD5Encoder.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Helma License Notice - * - * The contents of this file are subject to the Helma License - * Version 2.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://adele.helma.org/download/helma/license.txt - * - * Copyright 1998-2003 Helma Software. All Rights Reserved. - * - * $RCSfile$ - * $Author$ - * $Revision$ - * $Date$ - */ - -package helma.util; - -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - -/** - * - */ -public class MD5Encoder { - private static MessageDigest md; - - /** used by commandline script to create admin username & password */ - public static void main(String[] args) throws Exception { - if (args.length < 2) { - System.out.println("\n\nUsage: helma.util.MD5Encoder "); - System.out.println("Output:"); - System.out.println("adminUsername="); - System.out.println("adminPassword=\n"); - System.exit(0); - } - - System.out.println("adminUsername=" + encode(args[0])); - System.out.println("adminPassword=" + encode(args[1])); - } - - /** - * - * - * @param str ... - * - * @return ... - * - * @throws NoSuchAlgorithmException ... - */ - public static String encode(String str) throws NoSuchAlgorithmException { - return encode(str.getBytes()); - } - - /** - * - * - * @param message ... - * - * @return ... - * - * @throws NoSuchAlgorithmException ... - */ - public static String encode(byte[] message) throws NoSuchAlgorithmException { - md = MessageDigest.getInstance("MD5"); - - byte[] b = md.digest(message); - StringBuffer buf = new StringBuffer(b.length * 2); - - for (int i = 0; i < b.length; i++) { - int j = (b[i] < 0) ? (256 + b[i]) : b[i]; - - if (j < 16) { - buf.append("0"); - } - - buf.append(Integer.toHexString(j)); - } - - return buf.toString(); - } - - /** - * Convert a long to a byte array. - */ - public static byte[] toBytes(long n) { - byte[] b = new byte[8]; - - b[0] = (byte) (n); - n >>>= 8; - b[1] = (byte) (n); - n >>>= 8; - b[2] = (byte) (n); - n >>>= 8; - b[3] = (byte) (n); - n >>>= 8; - b[4] = (byte) (n); - n >>>= 8; - b[5] = (byte) (n); - n >>>= 8; - b[6] = (byte) (n); - n >>>= 8; - b[7] = (byte) (n); - - return b; - } -}