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 return convertHashToString(md5Bytes);
27 } catch (Exception e) {
30 if (inputStream != null) {
33 } catch (Exception e) { }
38 private static String convertHashToString(byte[] md5Bytes) {
39 String returnVal = "";
40 for (int i = 0; i < md5Bytes.length; i++) {
41 returnVal += Integer.toString(( md5Bytes[i] & 0xff ) + 0x100, 16).substring(1);