SafeAPI v1.20

com.safeapi
Class CryptoHash

java.lang.Object
  extended bycom.safeapi.CryptoCommon
      extended bycom.safeapi.CryptoHash

public final class CryptoHash
extends CryptoCommon

Hash APis Module


Constructor Summary
CryptoHash()
          Loads an instance of CryptoHash.
 
Method Summary
 String hashBufferHex(String sAlgorithm, byte[] bBuffer)
          Computes in one operation the digest value for the specified buffer and with the specified algorithm.
 void hashDataBuffer(byte[] bSubBuffer)
          Updates the digest using the specified array of bytes.
 byte[] hashDataBufferDigest()
          Completes the hash computation by performing final operations such as padding.
 void hashDataBufferInit(String sAlgorithm)
          Initializes a BufferDigest with specified algorithm (MD5 or SHA-1).
 byte[] hashDataFile(String sAlgorithm, String sFilePath)
          Returns the digest value for the specified file and with the specified algorithm.
 
Methods inherited from class com.safeapi.CryptoCommon
createSeedFile, getParameter, getRandomBytes, getRawError, getRegisteredError, getVersion, isOperationOK, setParameter, wipe
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CryptoHash

public CryptoHash()
Loads an instance of CryptoHash.

Method Detail

hashDataBufferInit

public void hashDataBufferInit(String sAlgorithm)
Initializes a BufferDigest with specified algorithm (MD5 or SHA-1).

Parameters:
sAlgorithm - The algorithm to use

hashDataBuffer

public void hashDataBuffer(byte[] bSubBuffer)
Updates the digest using the specified array of bytes.
You *must* have initialized the Digest with hashDataBufferInit(java.lang.String) first.

Parameters:
bSubBuffer - The bytes to add to the buffer to hash

hashDataBufferDigest

public byte[] hashDataBufferDigest()
Completes the hash computation by performing final operations such as padding. The digest is reset after this call is made.

Be careful! There is no control on the buffer length. This is of the developer responsibility to check if additions to the buffer had been done successfully

Returns:
The bytes issued from the digest of buffer

hashBufferHex

public String hashBufferHex(String sAlgorithm,
                            byte[] bBuffer)
Computes in one operation the digest value for the specified buffer and with the specified algorithm.
Two algorithms are implemented: MD5 and SHA-1

Parameters:
sAlgorithm - The algorithm used for the hash function
bBuffer - The byte array to add to the buffer to hash
Returns:
The hexidecimal digest associated to the buffer with specified algorithm

hashDataFile

public byte[] hashDataFile(String sAlgorithm,
                           String sFilePath)
Returns the digest value for the specified file and with the specified algorithm.
Two algorithms are implemented: MD5 and SHA-1

Parameters:
sAlgorithm - The algorithm used for the hash function
sFilePath - The path of the file to hash
Returns:
The digest associated to the file with specified algorithm

SafeAPI v1.20

Copyright © SafeLogic 2005