I want to create a program, which generates a MD5-hash from the input of a path. The code down below only creates a hash from the name of the path. How can I generate a MD5-hash from the input of the path? Thank you!
public static void main (String[]args) {
Scanner sc = new Scanner(System.in);
String path = sc.next();
System.out.println("MD5: "+MD5(path)); //Methode MD5 auf "path" angewandt
}
public static String MD5(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 (Exception e) {
throw new RuntimeException(e);
}
}