SHApublic final class SHA extends MessageDigest Implements the SHA-1 message digest algorithm. |
Fields Summary |
---|
private int[] | stateState needed for SHA hash. | private int[] | numState needed for SHA hash. | private int[] | countState needed for SHA hash. | private int[] | dataState needed for SHA hash. |
Constructors Summary |
---|
SHA()Create SHA digest object. // data block
reset();
|
Methods Summary |
---|
public java.lang.Object | clone()Clones the MessageDigest object.
SHA cpy = new SHA();
System.arraycopy(this.state, 0, cpy.state, 0, this.state.length);
System.arraycopy(this.num, 0, cpy.num, 0, this.num.length);
System.arraycopy(this.count, 0, cpy.count, 0, this.count.length);
System.arraycopy(this.data, 0, cpy.data, 0, this.data.length);
return cpy;
| public int | digest(byte[] buf, int offset, int len)Completes the hash computation by performing final operations
such as padding. The digest is reset after this call is made.
if (len < getDigestLength()) {
throw new DigestException("Buffer too short.");
}
// check the parameters to prevent a VM crash
int test = buf[offset] + buf[offset + getDigestLength() - 1];
nativeFinal(null, 0, 0, buf, offset, state, num, count, data);
return getDigestLength();
| public java.lang.String | getAlgorithm()Gets the message digest algorithm.
return "SHA-1";
| public int | getDigestLength()Gets the length (in bytes) of the hash.
return 20;
| private static native void | nativeFinal(byte[] inBuf, int inOff, int inLen, byte[] outBuf, int outOff, int[] state, int[] num, int[] count, int[] data)Generates a hash of all/last input data. Completes and returns the
hash compuatation after performing final operations such as padding.
The MessageDigest object is reset after this call.
| private static native void | nativeUpdate(byte[] inBuf, int inOff, int inLen, int[] state, int[] num, int[] count, int[] data)Accumulates a hash of the input data. This method is useful when
the input data to be hashed is not available in one byte array.
| public void | reset()Resets the MessageDigest to the initial state for further use.
// SHA1 initialization constants
state[0] = 0x67452301;
state[1] = 0xEFCDAB89;
state[2] = 0x98BADCFE;
state[3] = 0x10325476;
state[4] = 0xC3D2E1F0;
num[0] = 0;
count[0] = count[1] = 0;
for (int i = 0; i < data.length; i++)
data[i] = 0;
| public void | update(byte[] inBuf, int inOff, int inLen)Accumulates a hash of the input data. This method is useful when
the input data to be hashed is not available in one byte array.
if (inLen == 0) {
return;
}
// check parameters to avoid a VM crash
int test = inBuf[inOff] + inBuf[inLen - 1] + inBuf[inOff + inLen - 1];
nativeUpdate(inBuf, inOff, inLen, state, num, count, data);
|
|