+++ /dev/null
-package com.company;
-
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-
-
-public class MD5 {
-
- MD5(){}
- public static String digest(String filePath) {
- InputStream inputStream = null;
- try {
- inputStream = new FileInputStream(global.locationEsercizi+filePath);
- byte[] buffer = new byte[1024];
- MessageDigest digest = MessageDigest.getInstance("MD5");
- int numRead = 0;
- while (numRead != -1) {
- numRead = inputStream.read(buffer);
- if (numRead > 0)
- digest.update(buffer, 0, numRead);
- }
- byte [] md5Bytes = digest.digest();
- System.out.println(convertHashToString(md5Bytes));
- return convertHashToString(md5Bytes);
- } catch (Exception e) {
- return null;
- } finally {
- if (inputStream != null) {
- try {
- inputStream.close();
- } catch (Exception e) { }
- }
- }
- }
-
- private static String convertHashToString(byte[] md5Bytes) {
- String returnVal = "";
- for (int i = 0; i < md5Bytes.length; i++) {
- returnVal += Integer.toString(( md5Bytes[i] & 0xff ) + 0x100, 16).substring(1);
- }
- return returnVal;
- }
-}