I understand how it works but if I want to print out the MD5 as String how would I do that?
public static void getMD5(String fileName) throws Exception{ InputStream input = new FileInputStream(fileName); byte[] buffer = new byte[1024]; MessageDigest hash = MessageDigest.getInstance("MD5"); int read; do { read = input.read(buffer); if (read > 0) { hash.update(buffer, 0, read); } } while (read != -1); input.close(); }
You can get it writing less:
String hex = (new HexBinaryAdapter()).marshal(md5.digest(YOUR_STRING.getBytes()))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With