javacard.security
Class MessageDigest

java.lang.Object
  extended byjavacard.security.MessageDigest

public abstract class MessageDigest
extends Object

The MessageDigest class is the base class for hashing algorithms. Implementations of MessageDigest algorithms must extend this class and implement all the abstract methods.

A tear or card reset event resets a MessageDigest object to the initial state (state upon construction).


Field Summary
static byte ALG_MD5
          Message Digest algorithm MD5.
static byte ALG_RIPEMD160
          Message Digest algorithm RIPE MD-160.
static byte ALG_SHA
          Message Digest algorithm SHA.
 
Constructor Summary
protected MessageDigest()
          Protected Constructor
 
Method Summary
abstract  short doFinal(byte[] inBuff, short inOffset, short inLength, byte[] outBuff, short outOffset)
          Generates a hash of all/last input data.
abstract  byte getAlgorithm()
          Gets the Message digest algorithm.
static MessageDigest getInstance(byte algorithm, boolean externalAccess)
          Creates a MessageDigest object instance of the selected algorithm.
abstract  byte getLength()
          Returns the byte length of the hash.
abstract  void reset()
          Resets the MessageDigest object to the initial state for further use.
abstract  void update(byte[] inBuff, short inOffset, short inLength)
          Accumulates a hash of the input data.
 
Methods inherited from class java.lang.Object
equals
 

Field Detail

ALG_SHA

public static final byte ALG_SHA
Message Digest algorithm SHA.

See Also:
Constant Field Values

ALG_MD5

public static final byte ALG_MD5
Message Digest algorithm MD5.

See Also:
Constant Field Values

ALG_RIPEMD160

public static final byte ALG_RIPEMD160
Message Digest algorithm RIPE MD-160.

See Also:
Constant Field Values
Constructor Detail

MessageDigest

protected MessageDigest()
Protected Constructor

Method Detail

getInstance

public static final MessageDigest getInstance(byte algorithm,
                                              boolean externalAccess)
                                       throws CryptoException
Creates a MessageDigest object instance of the selected algorithm.

Parameters:
algorithm - the desired message digest algorithm. Valid codes listed in ALG_.. constants. See above.
externalAccess - if true indicates that the instance will be shared among multiple applet instances and that the MessageDigest instance will also be accessed (via a Shareable interface) when the owner of the MessageDigest instance is not the currently selected applet.
Returns:
the MessageDigest object instance of the requested algorithm.
Throws:
CryptoException - with the following reason codes:
  • CryptoException.NO_SUCH_ALGORITHM if the requested algorithm is not supported.

getAlgorithm

public abstract byte getAlgorithm()
Gets the Message digest algorithm.

Returns:
the algorithm code defined above.

getLength

public abstract byte getLength()
Returns the byte length of the hash.

Returns:
hash length

doFinal

public abstract short doFinal(byte[] inBuff,
                              short inOffset,
                              short inLength,
                              byte[] outBuff,
                              short outOffset)
Generates a hash of all/last input data. Completes and returns the hash computation after performing final operations such as padding. The MessageDigest object is reset to the initial state after this call is made.

The input and output buffer data may overlap.

Parameters:
inBuff - the input buffer of data to be hashed
inOffset - the offset into the input buffer at which to begin hash generation
inLength - the byte length to hash
outBuff - the output buffer, may be the same as the input buffer
outOffset - the offset into the output buffer where the resulting hash value begins
Returns:
number of bytes of hash output in outBuff

update

public abstract void update(byte[] inBuff,
                            short inOffset,
                            short inLength)
Accumulates a hash of the input data. This method requires temporary storage of intermediate results. In addition, if the input data length is not block aligned (multiple of block size) then additional internal storage may be allocated at this time to store a partial input data block. This may result in additional resource consumption and/or slow performance. This method should only be used if all the input data required for the hash is not available in one byte array. The doFinal() method is recommended whenever possible.

Parameters:
inBuff - the input buffer of data to be hashed
inOffset - the offset into the input buffer at which to begin hash generation
inLength - the byte length to hash
See Also:
doFinal(byte[], short, short, byte[], short)

reset

public abstract void reset()
Resets the MessageDigest object to the initial state for further use.



Java and all Java-based trademarks and logos are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries.