import java.io.*;
import java.security.*;
public class DigestRunnable implements Runnable {
private File input;
public DigestRunnable(File input) {
this.input = input;
}
public void run() {
try {
FileInputStream in = new FileInputStream(input);
MessageDigest sha = MessageDigest.getInstance("SHA");
DigestInputStream din = new DigestInputStream(in, sha);
int b;
while ((b = din.read()) != -1) ;
din.close();
byte[] digest = sha.digest();
StringBuffer result = new StringBuffer(input.toString());
result.append(": ");
for (int i = 0; i < digest.length; i++) {
result.append(digest[i] + " ");
}
System.out.println(result);
}
catch (IOException ex) {
System.err.println(ex);
}
catch (NoSuchAlgorithmException ex) {
System.err.println(ex);
}
}
public static void main(String[] args) {
for (int i = 0; i < args.length; i++) {
File f = new File(args[i]);
DigestRunnable dr = new DigestRunnable(f);
Thread t = new Thread(dr);
t.start();
}
}
}
|