1 package com.example.furt.myapplication;
3 import android.os.Environment;
5 import java.io.FileInputStream;
6 import java.io.InputStream;
7 import java.security.MessageDigest;
14 /*public static String digest(String fileName) throws NoSuchAlgorithmException, IOException
17 MessageDigest md = MessageDigest.getInstance("MD5");
18 return getDigest(new FileInputStream("/var/www/html/esercizi/"+fileName), md, 2048);
21 public static String getDigest(InputStream is, MessageDigest md, int byteArraySize) throws NoSuchAlgorithmException, IOException
24 byte[] bytes = new byte[byteArraySize];
26 while ((numBytes = is.read(bytes)) != -1) {
27 md.update(bytes, 0, numBytes);
29 byte[] digest = md.digest();
30 String result = new String(Hex.encodeHex(digest));
33 public static String digest(String filePath) {
34 InputStream inputStream = null;
36 inputStream = new FileInputStream(Environment.getExternalStorageDirectory()+"/tesiEs/"+filePath);
37 byte[] buffer = new byte[1024];
38 MessageDigest digest = MessageDigest.getInstance("MD5");
40 while (numRead != -1) {
41 numRead = inputStream.read(buffer);
43 digest.update(buffer, 0, numRead);
45 byte [] md5Bytes = digest.digest();
46 return convertHashToString(md5Bytes);
47 } catch (Exception e) {
50 if (inputStream != null) {
53 } catch (Exception e) { }
58 private static String convertHashToString(byte[] md5Bytes) {
59 String returnVal = "";
60 for (int i = 0; i < md5Bytes.length; i++) {
61 returnVal += Integer.toString(( md5Bytes[i] & 0xff ) + 0x100, 16).substring(1);