1 /*
2  * @(#) $Id: ComputeDigest.java,v 1.2 2003/07/08 08:13:52 pankaj Exp $
3  *
4  * Copyright (c) 2002-03 by Pankaj Kumar (http://www.pankaj-k.net). 
5  * All rights reserved.
6  *
7  * The license governing the use of this file can be found in the 
8  * root directory of the containing software.
9  */
10import java.security.MessageDigest;
11import java.io.FileInputStream;
12
13public class ComputeDigest {
14    public static void main(String[] unused) throws Exception{
15        String datafile = "ComputeDigest.java";
16
17        MessageDigest md = MessageDigest.getInstance("SHA1");
18        FileInputStream fis = new FileInputStream(datafile);
19        byte[] dataBytes = new byte[1024];
20        int nread = fis.read(dataBytes);
21        while (nread > 0) {
22            md.update(dataBytes, 0, nread);
23            nread = fis.read(dataBytes);
24        };
25        byte[] mdbytes = md.digest();
26        System.out.println("Digest(in hex):: " + Util.byteArray2Hex(mdbytes));
27    }
28}