import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MD5Hashing {
public static String hashString(String input) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(input.getBytes());
byte[] digest = md.digest();
StringBuilder hexString = new StringBuilder();
for (byte b : digest) {
hexString.append(String.format("%02x", b));
}
return hexString.toString();
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException("MD5 hashing algorithm not found", e);
}
}
public static void main(String[] args) {
String input = "Hello World";
String hashedString = hashString(input);
System.out.println("Original String: " + input);
System.out.println("Hashed String: " + hashedString);
}
}