Java tutorial
//package com.java2s; import java.io.IOException; import java.io.InputStream; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { private static final char[] hexDigits = "0123456789abcdef".toCharArray(); public static String hashStream(InputStream in, String hash) throws IOException { MessageDigest md5 = null; try { md5 = MessageDigest.getInstance(hash); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } int bsize = 4096; byte[] buffer = new byte[bsize]; int length; while ((length = in.read(buffer, 0, bsize)) > 0) { md5.update(buffer, 0, length); } return toHex(md5.digest()); } public static String hashStream(InputStream in) throws IOException { return hashStream(in, "MD5"); } public static String toHex(byte[] arr) { final char[] str = new char[arr.length * 2]; for (int i = 0; i < arr.length; i++) { final int v = arr[i] & 0xff; str[2 * i] = hexDigits[v >>> 4]; str[2 * i + 1] = hexDigits[v & 0x0f]; } return new String(str); } }