23.07.2013 Views

Java IO.pdf - Nguyen Dang Binh

Java IO.pdf - Nguyen Dang Binh

Java IO.pdf - Nguyen Dang Binh

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Java</strong> I/O<br />

algorithms. Depending on which service providers are installed, you may or may not have all<br />

of these. The JDK 1.1 includes SHA-1 (which is the same as SHA) and MD5 but not MD2.<br />

RSA's paywareCrypto-J cryptography library also supports MD2. (See<br />

http://www.rsa.com/rsa/products/jsafe/.)<br />

Name Algorithm<br />

SHA-<br />

1<br />

Table 10.1. Message Digest Algorithms in <strong>Java</strong> 1.1<br />

The Secure Hash Algorithm, as defined in Secure Hash Standard, NIST FIPS 180-1 (National Institute of<br />

Standards and Technology Federal Information Processing Standards Publications 180-1); produces 20byte<br />

digests; see http://www.itl.nist.gov/div897/pubs/fip180-1.htm<br />

SHA Another name for SHA-1<br />

RSA-MD2 as defined in RFC 1319 and RFC 1423 (RFC 1423 corrects a mistake in RFC 1319); produces<br />

MD2 16-byte digests; suitable for use with digital signatures; see http://www.faqs.org/rfcs/rfc1319.html and<br />

http://www.faqs.org/rfcs/rfc1423.html<br />

RSA-MD5 as defined in RFC 1321; produces 16-byte digests; quite fast on 32-bit machines; see<br />

MD5<br />

http://www.faqs.org/rfcs/rfc1321.html<br />

10.2.1 Calculating Message Digests<br />

There are four steps to calculating a hash code for a file or other sequential set of bytes with a<br />

MessageDigest object; Figure 10.1 shows a flow chart for this process.<br />

1. Pass the name of the algorithm you want to use to the static<br />

MessageDigest.getInstance() factory method to get a new MessageDigest object.<br />

2. Feed bytes into the update() method.<br />

3. If more data remains, repeat step 2.<br />

4. Invoke a digest() method to complete computation of the digest and return it as an<br />

array of bytes.<br />

196

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!