3 import java.io.FileInputStream;
4 import java.io.IOException;
5 import java.io.InputStream;
6 import java.security.MessageDigest;
7 import java.security.NoSuchAlgorithmException;
13 public static String digest(String filePath) {
14 InputStream inputStream = null;
16 inputStream = new FileInputStream(global.locationEsercizi+filePath);
17 byte[] buffer = new byte[1024];
18 MessageDigest digest = MessageDigest.getInstance("MD5");
20 while (numRead != -1) {
21 numRead = inputStream.read(buffer);
23 digest.update(buffer, 0, numRead);
25 byte [] md5Bytes = digest.digest();
26 System.out.println(convertHashToString(md5Bytes));
27 return convertHashToString(md5Bytes);
28 } catch (Exception e) {
31 if (inputStream != null) {
34 } catch (Exception e) { }
39 private static String convertHashToString(byte[] md5Bytes) {
40 String returnVal = "";
41 for (int i = 0; i < md5Bytes.length; i++) {
42 returnVal += Integer.toString(( md5Bytes[i] & 0xff ) + 0x100, 16).substring(1);