public class SHA extends AbstractMessageDigest
A message digest algorithm represents the functionality of an oneway hash function for computing a fixed sized data value (message digest, hash) from input data of arbitrary size. The length of the resulting hash value usually is shorter than the length of the input data. Using a oneway hash function will make it easy to compute the hash from the given data, but hard to go the reverse way for calculating the input data when only the hash is known. Furthermore, a proper hash function should avoid any collision, meaning that it has to be hard to find two different messages producing the same hash value.
The Secure Hash Algorithm (SHA) produces a 160Bit hash value.
Like MD5, the SHA algorithm processes the data in blocks of 512Bit length. First the input data is properly padded and subsequently extended by a 64Bit representation of the data's original length to become a multiple of 512 Bit. The resulting text is divided into 512Bit blocks, each of it again divided into sixteen 32Bit subblocks. Each of the 512Bit blocks is processed in a main loop. Input of the main loop are five 32Bit variables, which are properly initialized with constant values for the first main loop run processing the first 512Bit block. Each main loop run is featured with a new 512Bit block as long as there blocks available. Each main loop run produces an output of five 32Bit variables which are added to the initial five 32bit variables to be fed into the next main loop run for processing the next 512Bit block. When no further 512Bit block is available, the algorithm leaves the main loop and calculates the final 160Bit hash output by concatenating the five 32Bit variables resulting from the last main loop run. The main loop consists of four rounds based on a certain nonlinear function (see "Applied Cryptography", Bruce Schneier, ISBN 0471597562).
For digital signature processing, the SHA algorithm is recommended by FIPS to be used together with the Digital Signature Algorithm (DSA) for computing a 160Bit hash value of data input of any length shorter than 2^{64} Bits, which subsequently is processed using the DSA algorithm to produce the signature.
This class extends the java.security.MessageDigest
class and
applications should use one of the getInstance
methods presented
there to create a MessageDigestSHA object. Generally, an application wishing
to compute the message digest of some data has to perform three steps:
getInstance
method, e.g.:
MessageDigest sha = MessageDigest.getInstance("SHA");
update
methods, e.g:
sha.update(m1); sha.update(m2); ...
digest
methods:
byte[] hash_value = sha.digest();
There are several ways for combining update
and digest
methods for computing a message digest. Since this class implements the
Cloneable
interface, SHA MessageDigest objects may be used for
compute intermediate hashes through cloning (see
http://java.sun.com/products/JDK/1.1/docs/guide/security/CryptoSpec.html).
When the hash value successfully has been computed, the SHA MessageDigest object automatically resets for being able to be supplied with new data to be hashed.
The SHA algorithm may be combined with the RSA publickey algorithm to be
used as digital signature algorithm ShaRSASignature
).
Constructor and Description 

SHA()
Creates a new SHA message digest object.

Modifier and Type  Method and Description 

java.lang.Object 
clone()
Returns a clone of this SHA Object.

void 
engineReset()
SPI: Resets this SHA message digest object for being supplied
with new data.

engineDigest, engineGetDigestLength, engineUpdate, engineUpdate
public SHA()
for creating a messageDigest object.MessageDigest.getInstance("SHA");
MessageDigest.getInstance(java.lang.String)
public java.lang.Object clone()
clone
in class AbstractMessageDigest
public void engineReset()
This method is called by engineDigest
after the actual hash computation has been finished to automatically reset the
message digest object for being supplied with new data for starting a new hash
computation.
engineReset
in class AbstractMessageDigest
MessageDigestSpi.engineReset()
5.5 (c) 2002 IAIK, (c) 2003  2017 SIC 