May 2003
Intermediate to advanced
384 pages
9h 37m
English
This section presents several examples to illustrate further how you can use the classes discussed in this chapter.
The first example computes a message digest, or hash, using the SHA-1 algorithm. Suppose that you have a message composed of three byte arrays: i1, i2, and i3. First, you create a properly initialized message digest object. Then you run the three byte arrays through the message digest object to calculate the hash, as follows:
MessageDigest sha = MessageDigest.getInstance("SHA-1");
sha.update(i1);
sha.update(i2);
sha.update(i3);
byte[] hash = sha.digest();
The call to the digest method signals the end of the input message and causes the digest to be calculated. An alternative ...
Read now
Unlock full access