import java.io.*; import java.nio.channels.*; import java.util.*; import java.util.jar.*; import java.security.MessageDigest; public class MD5Test { public static void main(String[] args) { try { MessageDigest md = MessageDigest.getInstance("MD5"); JarFile jar = new JarFile (args[0]); int count = 0; { Enumeration entries = jar.entries(); while (entries.hasMoreElements()) { JarEntry classfile = (JarEntry)entries.nextElement(); if (classfile.getName().endsWith(".class")) count++; } } Enumeration entries = jar.entries(); while (entries.hasMoreElements()) { JarEntry classfile = (JarEntry)entries.nextElement(); if (classfile.getName().endsWith(".class")) { InputStream str = jar.getInputStream(classfile); int length = (int) classfile.getSize(); if (length == -1) throw new EOFException(); byte[] data = new byte[length]; int pos = 0; while (length - pos > 0) { int len = str.read(data, pos, length - pos); if (len == -1) throw new EOFException("Not enough data reading from: " + classfile.getName()); pos += len; } System.out.println(classfile.getName() + " -> " + bytesToString(md.digest(data))); } } } catch (Exception e) { e.printStackTrace(); } } static String bytesToString(byte[] b) { StringBuffer hexBytes = new StringBuffer(); int length = b.length; for (int i = 0; i < length; ++i) hexBytes.append(Integer.toHexString(b[i] & 0xff)); return hexBytes.toString(); } }