org.springframework.extensions.surf.util
Class MD5

java.lang.Object
  extended by org.springframework.extensions.surf.util.MD5

public class MD5
extends Object

The MD5 utility class computes the MD5 digest (aka: "hash") of a block of data; an MD5 digest is a 32-char ASCII string. The synchronized/static function "Digest" is useful for situations where lock contention in the application is not expected to be an issue. The unsynchronized/non-static method "digest" is useful in a multi-threaded program that wanted to avoid locking by creating an MD5 object for exclusive use by a single thread.

  EXAMPLE 1:  Static usage

      import org.springframework.extensions.surf.util.MD5;
      String x = MD5.Digest("hello".getBytes());


  EXAMPLE 2:  Per-thread non-static usage

      import org.springframework.extensions.surf.util.MD5;
      MD5 md5 = new MD5();
      ...
      String x = md5.digest("hello".getBytes());

 


Constructor Summary
MD5()
          Constructor for use with the unsynchronized/non-static method "digest" method.
 
Method Summary
 String digest(byte[] dataToHash)
          Non-threadsafe MD5 digest (hashing) function
static String Digest(byte[] dataToHash)
          Thread-safe static digest (hashing) function.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MD5

public MD5()
Constructor for use with the unsynchronized/non-static method "digest" method. Note that the "digest" function is not thread-safe, so if you want to use it, every thread must create its own MD5 instance. If you don't want to bother & are willing to deal with the potential for lock contention, use the synchronized static "Digest" function instead of creating an instance via this constructor.

Method Detail

Digest

public static String Digest(byte[] dataToHash)
Thread-safe static digest (hashing) function. If you want to avoid lock contention, create an instance of MD5 per-thead, anc call the unsynchronized method 'digest' instead.


digest

public String digest(byte[] dataToHash)
Non-threadsafe MD5 digest (hashing) function



Copyright © 2009 SpringSource, Inc. All Rights Reserved.