org.riotfamily.common.util
Class HashUtils

java.lang.Object
  extended by org.riotfamily.common.util.HashUtils

public final class HashUtils
extends Object

Utility class that simplifies the generation of MD5 and SHA-1 hashes.


Field Summary
static String MD5
           
static String SHA1
           
 
Method Summary
static String hash(byte[] data, String algorithm)
          Hashes a byte array using the specified algorithm and returns the result as a String of hexadecimal numbers.
static String hash(InputStream in, String algorithm)
          Hashes data read from an InputStream using the specified algorithm and returns the result as a String of hexadecimal numbers.
static String hash(String data, String algorithm)
          Hashes a String using the specified algorithm and returns the result as a String of hexadecimal numbers.
static String md5(byte[] data)
          Hashes a byte array using the MD5 algorithm and returns the result as a String of hexadecimal numbers.
static String md5(InputStream in)
          Hashes an InputStream using the MD5 algorithm and returns the result as a String of hexadecimal numbers.
static String md5(String data)
          Hashes a String using the MD5 algorithm and returns the result as a String of hexadecimal numbers.
static String sha1(byte[] data)
          Hashes a byte array using the SHA-1 algorithm and returns the result as a String of hexadecimal numbers.
static String sha1(String data)
          Hashes a String using the SHA-1 algorithm and returns the result as a String of hexadecimal numbers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MD5

public static final String MD5
See Also:
Constant Field Values

SHA1

public static final String SHA1
See Also:
Constant Field Values
Method Detail

md5

public static String md5(String data)
Hashes a String using the MD5 algorithm and returns the result as a String of hexadecimal numbers.


md5

public static String md5(byte[] data)
Hashes a byte array using the MD5 algorithm and returns the result as a String of hexadecimal numbers.


md5

public static String md5(InputStream in)
                  throws IOException
Hashes an InputStream using the MD5 algorithm and returns the result as a String of hexadecimal numbers.

Throws:
IOException

sha1

public static String sha1(String data)
Hashes a String using the SHA-1 algorithm and returns the result as a String of hexadecimal numbers.


sha1

public static String sha1(byte[] data)
Hashes a byte array using the SHA-1 algorithm and returns the result as a String of hexadecimal numbers.


hash

public static String hash(String data,
                          String algorithm)
Hashes a String using the specified algorithm and returns the result as a String of hexadecimal numbers.

Parameters:
data - the String to compute the hash of
Returns:
the computed hash

hash

public static String hash(byte[] data,
                          String algorithm)
Hashes a byte array using the specified algorithm and returns the result as a String of hexadecimal numbers.

Parameters:
data - the bytes to compute the hash of
Returns:
the computed hash

hash

public static String hash(InputStream in,
                          String algorithm)
                   throws IOException
Hashes data read from an InputStream using the specified algorithm and returns the result as a String of hexadecimal numbers.

Parameters:
in - the stream to read the data from
Returns:
the computed hash
Throws:
IOException