Removed standalone MD5Encoder implementation and replaced usage of it with Apache Commons Codec.

This commit is contained in:
Daniel Ruthardt 2010-12-11 01:31:39 +01:00 committed by Tobi Schäfer
parent 5abe737912
commit 37307708fd
4 changed files with 9 additions and 111 deletions

View file

@ -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)));
}

View file

@ -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) {

View file

@ -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) {

View file

@ -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 <username> <password>");
System.out.println("Output:");
System.out.println("adminUsername=<encoded username>");
System.out.println("adminPassword=<encoded password>\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;
}
}