org.springframework.util
Class DigestUtils

java.lang.Object
  extended by org.springframework.util.DigestUtils

public abstract class DigestUtils
extends java.lang.Object

Miscellaneous methods for calculating digests.

Mainly for internal use within the framework; consider Apache Commons Codec for a more comprehensive suite of digest utilities.

Since:
3.0
Author:
Arjen Poutsma
See Also:
org.apache.commons.codec.digest.DigestUtils

Field Summary
private static char[] HEX_CHARS
           
private static java.lang.String MD5_ALGORITHM_NAME
           
 
Constructor Summary
DigestUtils()
           
 
Method Summary
private static java.lang.StringBuilder appendDigestAsHex(java.lang.String algorithm, byte[] bytes, java.lang.StringBuilder builder)
           
static java.lang.StringBuilder appendMd5DigestAsHex(byte[] bytes, java.lang.StringBuilder builder)
          Append a hexadecimal string representation of the MD5 digest of the given bytes to the given StringBuilder.
private static byte[] digest(java.lang.String algorithm, byte[] bytes)
           
private static char[] digestAsHexChars(java.lang.String algorithm, byte[] bytes)
           
private static java.lang.String digestAsHexString(java.lang.String algorithm, byte[] bytes)
           
private static char[] encodeHex(byte[] bytes)
           
private static java.security.MessageDigest getDigest(java.lang.String algorithm)
          Creates a new MessageDigest with the given algorithm.
static byte[] md5Digest(byte[] bytes)
          Calculate the MD5 digest of the given bytes.
static java.lang.String md5DigestAsHex(byte[] bytes)
          Return a hexadecimal string representation of the MD5 digest of the given bytes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MD5_ALGORITHM_NAME

private static final java.lang.String MD5_ALGORITHM_NAME
See Also:
Constant Field Values

HEX_CHARS

private static final char[] HEX_CHARS
Constructor Detail

DigestUtils

public DigestUtils()
Method Detail

md5Digest

public static byte[] md5Digest(byte[] bytes)
Calculate the MD5 digest of the given bytes.

Parameters:
bytes - the bytes to calculate the digest over
Returns:
the digest

md5DigestAsHex

public static java.lang.String md5DigestAsHex(byte[] bytes)
Return a hexadecimal string representation of the MD5 digest of the given bytes.

Parameters:
bytes - the bytes to calculate the digest over
Returns:
a hexadecimal digest string

appendMd5DigestAsHex

public static java.lang.StringBuilder appendMd5DigestAsHex(byte[] bytes,
                                                           java.lang.StringBuilder builder)
Append a hexadecimal string representation of the MD5 digest of the given bytes to the given StringBuilder.

Parameters:
bytes - the bytes to calculate the digest over
builder - the string builder to append the digest to
Returns:
the given string builder

getDigest

private static java.security.MessageDigest getDigest(java.lang.String algorithm)
Creates a new MessageDigest with the given algorithm. Necessary because MessageDigest is not thread-safe.


digest

private static byte[] digest(java.lang.String algorithm,
                             byte[] bytes)

digestAsHexString

private static java.lang.String digestAsHexString(java.lang.String algorithm,
                                                  byte[] bytes)

appendDigestAsHex

private static java.lang.StringBuilder appendDigestAsHex(java.lang.String algorithm,
                                                         byte[] bytes,
                                                         java.lang.StringBuilder builder)

digestAsHexChars

private static char[] digestAsHexChars(java.lang.String algorithm,
                                       byte[] bytes)

encodeHex

private static char[] encodeHex(byte[] bytes)