Class MD5


  • public class MD5
    extends java.lang.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..alfresco.util.MD5;
          String x = MD5.Digest("hello".getBytes());
    
    
      EXAMPLE 2:  Per-thread non-static usage
    
          import org..alfresco.util.MD5;
          MD5 md5 = new MD5();
          ...
          String x = md5.digest("hello".getBytes());
    
     
    • Constructor Summary

      Constructors 
      Constructor Description
      MD5()
      Constructor for use with the unsynchronized/non-static method "digest" method.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String digest​(byte[] dataToHash)
      Non-threadsafe MD5 digest (hashing) function
      static java.lang.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 java.lang.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 java.lang.String digest​(byte[] dataToHash)
        Non-threadsafe MD5 digest (hashing) function