Does anyone know proven and functional functions for what I need?
I have a list of Files stored in a variable and when it is on it to know if i is a folder or file:
if (listFile[i].isDirectory()) {
//md5 = (JSONObject)parser.parse(getMD5(listFile[i].getAbsolutePath()));
//obj.put("md5", md5);
obj.put("type", "folder");
obj.put("path", listFile[i].getAbsolutePath());
JSONArray contentSon = new JSONArray();
obj.put("Content", contentSon);
drawJsonTree(listFile[i], contentSon);
numDir++;
} else if (listFile[i].isFile()) {
obj.put("type", "file");
obj.put("path", listFile[i].getAbsolutePath());
numFiles++;
}
I need to encrypt anything to MD5, either a File or the path to a directory ...
I have this function that I take from Google for the topic of routes to directories:
public static String getMD5(String input) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] messageDigest = md.digest(input.getBytes());
BigInteger number = new BigInteger(1, messageDigest);
String hashtext = number.toString(16);
while (hashtext.length() < 32) {
hashtext = "0" + hashtext;
}
return hashtext;
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
}
But I'm finding it hard to find one for the Files ....
Example of if it comes out of the "else if" (I need you to encrypt that file)
"type": "file", "name": "JV.Coldview.DTFtoPDF.Service.AMCOX.Compatible.jar", "md5": "........."
Both functions have to be useful for JAVA 7 because that's what the machine has!
Thank you very much!