public class PretendedMessageDigest
extends java.security.MessageDigest
implements java.lang.Cloneable
This class does not actually compute a message digest value. Calling one of the
update
methods only will write the supplied data to a internal
buffer. Calling the final digest
method only will return the
contents of this buffer; no digest computation ever has been performed.
Intended purpose of this class is to allow usage of MessageDigest engines
with raw signature engines where the MessageDigest value already has been
calculated outside the Signature engine and therefore no digest computation has
to be done by the Signature engine's internal digest machine.
Since this class does not (cannot) know the hash algorithm actually used
for hashing the data an application has to take care to provide a proper
hash value when calling an update
method; no check is (can be)
performed if the supplied hash value corresponds to the hash algorithm
in use (e.g. has the correct length).
Constructor and Description |
---|
PretendedMessageDigest()
Default constructor.
|
PretendedMessageDigest(java.lang.String name,
int digestLength)
Creates a PretendedMessageDigest engine with given name and digest length.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
clone()
Returns a clone of this object.
|
protected byte[] |
engineDigest()
Returns the final digest value.
|
int |
engineGetDigestLength()
SPI: Returns the length of the digest in bytes.
|
protected void |
engineReset()
Resets the buffer.
|
protected void |
engineUpdate(byte input)
SPI: Updates the internal buffer with the specified byte.
|
protected void |
engineUpdate(byte[] input,
int offset,
int len)
SPI: Updates the internal buffer with the specified number of
bytes, beginning at the specified offset within the given byte array.
|
public PretendedMessageDigest()
public PretendedMessageDigest(java.lang.String name, int digestLength)
name
- the name of the digest algorithm this class representsdigestLength
- the length of the digest value produce by this engineprotected final void engineUpdate(byte input)
engineUpdate
in class java.security.MessageDigestSpi
input
- the byte to be written to the internal bufferjava.lang.IllegalArgumentException
- if this engine has a defined
digest size and the input data provided so far exceeds
the digest sizeprotected final void engineUpdate(byte[] input, int offset, int len)
engineUpdate
in class java.security.MessageDigestSpi
input
- the byte array holding the data to be used for this update
operation.offset
- the offset, indicating the start position within the given
byte array.len
- the number of bytes to be obtained from the given byte array,
starting at the given position.java.lang.IllegalArgumentException
- if this engine has a defined
digest size and the input data provided so far exceeds
the digest sizeprotected byte[] engineDigest()
engineDigest
in class java.security.MessageDigestSpi
public int engineGetDigestLength()
digest
already has been
called. Otherwise this method may return 0.engineGetDigestLength
in class java.security.MessageDigestSpi
protected void engineReset()
engineReset
in class java.security.MessageDigestSpi
public java.lang.Object clone()
clone
in class java.security.MessageDigest