com.sibvisions.util
Class SecureHash

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

public class SecureHash
extends java.lang.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 java.lang.String MD2
          the MD2 hash algorithm.
static java.lang.String MD4
          the MD4 hash algorithm.
static java.lang.String MD5
          the MD5 hash algorithm.
static java.lang.String SHA
          the SHA hash algorithm.
static java.lang.String SHA_256
          the SHA-256 hash algorithm.
static java.lang.String SHA_384
          the SHA-384 hash algorithm.
static java.lang.String SHA_512
          the SHA-512 hash algorithm.
 
Constructor Summary
SecureHash(java.lang.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(java.io.InputStream pData)
          Adds data to the digest.
 java.lang.String getHash()
          Gets the current hash.
static java.lang.String getHash(java.lang.String pAlgorithm, byte[] pData)
          Gets the hash of specific data.
static java.lang.String getHash(java.lang.String pAlgorithm, java.io.InputStream pData)
          Gets the hash of all content read from an InputStream.
 byte[] getRawHash()
          Gets the current raw hash.
static byte[] getRawHash(java.lang.String pAlgorithm, byte[] pData)
          Gets the raw hash of specific data.
static byte[] getRawHash(java.lang.String pAlgorithm, java.io.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 java.lang.String MD2
the MD2 hash algorithm.

See Also:
Constant Field Values

MD4

public static final java.lang.String MD4
the MD4 hash algorithm.

See Also:
Constant Field Values

MD5

public static final java.lang.String MD5
the MD5 hash algorithm.

See Also:
Constant Field Values

SHA

public static final java.lang.String SHA
the SHA hash algorithm.

See Also:
Constant Field Values

SHA_256

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

See Also:
Constant Field Values

SHA_384

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

See Also:
Constant Field Values

SHA_512

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

See Also:
Constant Field Values
Constructor Detail

SecureHash

public SecureHash(java.lang.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 java.lang.String getHash(java.lang.String pAlgorithm,
                                       java.io.InputStream pData)
                                throws java.security.NoSuchAlgorithmException,
                                       java.io.IOException
Gets the hash of all content read from an InputStream.

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

getRawHash

public static byte[] getRawHash(java.lang.String pAlgorithm,
                                java.io.InputStream pData)
                         throws java.security.NoSuchAlgorithmException,
                                java.io.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:
java.security.NoSuchAlgorithmException - specified algorithm is not available
java.io.IOException - if an error occurs during reading from the stream

getHash

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

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

getRawHash

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

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

add

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

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

add

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

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

reset

public void reset()
Resets the digest.


getHash

public java.lang.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.