[jboss-cvs] jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/util ...
Christian Bauer
christian at hibernate.org
Thu Jun 21 07:05:49 EDT 2007
User: cbauer
Date: 07/06/21 07:05:49
Modified: examples/wiki/src/main/org/jboss/seam/wiki/util Hash.java
Log:
Make it deploy and run on latest Seam CVS, still some bugs
Revision Changes Path
1.3 +23 -4 jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/util/Hash.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Hash.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/util/Hash.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- Hash.java 18 Mar 2007 19:01:15 -0000 1.2
+++ Hash.java 21 Jun 2007 11:05:49 -0000 1.3
@@ -2,7 +2,6 @@
import java.security.MessageDigest;
-import org.apache.commons.codec.binary.Hex;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.AutoCreate;
@@ -11,7 +10,7 @@
* Should also iterate the hashing a few thousand times to make brute force
* attacks more difficult. Basically, implement user password encryption with
* the same technique as on a typical Linux distribution.
- *
+ * <p/>
* TODO: Make this more secure - before releasing to public and breaking all stored passwords!
*/
@Name("hashUtil")
@@ -20,12 +19,17 @@
String hashFunction = "MD5";
String charset = "UTF-8";
+ private static final char[] DIGITS = {
+ '0', '1', '2', '3', '4', '5', '6', '7',
+ '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
+ };
+
public String hash(String text) {
try {
MessageDigest md = MessageDigest.getInstance(hashFunction);
md.update(text.getBytes(charset));
byte[] raw = md.digest();
- return new String(Hex.encodeHex(raw));
+ return new String(encodeHex(raw));
}
catch (Exception e) {
throw new RuntimeException(e);
@@ -48,4 +52,19 @@
this.hashFunction = hashFunction;
}
+ public static char[] encodeHex(byte[] data) {
+
+ int l = data.length;
+
+ char[] out = new char[l << 1];
+
+ // two characters form the hex value.
+ for (int i = 0, j = 0; i < l; i++) {
+ out[j++] = DIGITS[(0xF0 & data[i]) >>> 4];
+ out[j++] = DIGITS[0x0F & data[i]];
+ }
+
+ return out;
+ }
+
}
More information about the jboss-cvs-commits
mailing list