com.sibvisions.util
Class SecureHash

java.lang.Object
  extended by com.sibvisions.util.SecureHash

public class SecureHash
extends Object

The SecureHash class provides the functionality of a message digest algorithm, such as MD5 or SHA. Message digests are secure one-way hash functions that take arbitrary-sized data and output a fixed-length hash value.

See Also:
MessageDigest

Field Summary
static String MD2
          the MD2 hash algorithm.
static String MD4
          the MD4 hash algorithm.
static String MD5
          the MD5 hash algorithm.
static String SHA
          the SHA hash algorithm.
static String SHA_256
          the SHA-256 hash algorithm.
static String SHA_384
          the SHA-384 hash algorithm.
static String SHA_512
          the SHA-512 hash algorithm.
 
Constructor Summary
SecureHash(String pAlgorithm)
          Creates a new instance of SecureHash for a specific hash algorithm.
 
Method Summary
 void add(byte[] pData)
          Adds data to the digest.
 void add(InputStream pData)
          Adds data to the digest.
 String getHash()
          Gets the current hash.
static String getHash(String pAlgorithm, byte[] pData)
          Gets the hash of specific data.
static String getHash(String pAlgorithm, InputStream pData)
          Gets the hash of all content read from an InputStream.
 byte[] getRawHash()
          Gets the current raw hash.
static byte[] getRawHash(String pAlgorithm, byte[] pData)
          Gets the raw hash of specific data.
static byte[] getRawHash(String pAlgorithm, InputStream pData)
          Gets the raw hash of all content read from an InputStream.
 void reset()
          Resets the digest.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MD2

public static final String MD2
the MD2 hash algorithm.

See Also:
Constant Field Values

MD4

public static final String MD4
the MD4 hash algorithm.

See Also:
Constant Field Values

MD5

public static final String MD5
the MD5 hash algorithm.

See Also:
Constant Field Values

SHA

public static final String SHA
the SHA hash algorithm.

See Also:
Constant Field Values

SHA_256

public static final String SHA_256
the SHA-256 hash algorithm.

See Also:
Constant Field Values

SHA_384

public static final String SHA_384
the SHA-384 hash algorithm.

See Also:
Constant Field Values

SHA_512

public static final String SHA_512
the SHA-512 hash algorithm.

See Also:
Constant Field Values
Constructor Detail

SecureHash

public SecureHash(String pAlgorithm)
Creates a new instance of SecureHash for a specific hash algorithm.

Parameters:
pAlgorithm - the hash algorithm MD5 SHA
Method Detail

getHash

public static String getHash(String pAlgorithm,
                             InputStream pData)
                      throws NoSuchAlgorithmException,
                             IOException
Gets the hash of all content read from an InputStream.

Parameters:
pAlgorithm - the hash algorithm
pData - the data stream
Returns:
the hash
Throws:
NoSuchAlgorithmException - specified algorithm is not available
IOException - if an error occurs during reading from the stream

getRawHash

public static byte[] getRawHash(String pAlgorithm,
                                InputStream pData)
                         throws NoSuchAlgorithmException,
                                IOException
Gets the raw hash of all content read from an InputStream.

Parameters:
pAlgorithm - the hash algorithm
pData - the data stream
Returns:
the raw hash
Throws:
NoSuchAlgorithmException - specified algorithm is not available
IOException - if an error occurs during reading from the stream

getHash

public static String getHash(String pAlgorithm,
                             byte[] pData)
                      throws NoSuchAlgorithmException
Gets the hash of specific data.

Parameters:
pAlgorithm - the hash algorithm
pData - the data
Returns:
the hash
Throws:
NoSuchAlgorithmException - specified algorithm is not available

getRawHash

public static byte[] getRawHash(String pAlgorithm,
                                byte[] pData)
                         throws NoSuchAlgorithmException
Gets the raw hash of specific data.

Parameters:
pAlgorithm - the hash algorithm
pData - the data
Returns:
the raw hash
Throws:
NoSuchAlgorithmException - specified algorithm is not available

add

public void add(InputStream pData)
         throws NoSuchAlgorithmException,
                IOException
Adds data to the digest.

Parameters:
pData - the data stream
Throws:
NoSuchAlgorithmException
NoSuchAlgorithmException - specified algorithm is not available
IOException - if an error occurs during reading from the stream

add

public void add(byte[] pData)
         throws NoSuchAlgorithmException
Adds data to the digest.

Parameters:
pData - the data
Throws:
NoSuchAlgorithmException - specified algorithm is not available

reset

public void reset()
Resets the digest.


getHash

public String getHash()
Gets the current hash.

Returns:
the hash for the current data

getRawHash

public byte[] getRawHash()
Gets the current raw hash.

Returns:
the raw hash for the current data


Copyright © 2009 SIB Visions GmbH. All Rights Reserved.