@Test public void testGetMD5() throws Exception { System.out.println("745513a53af2befe3dc00d0341d80ca6"); System.out.println(HashTool.getMD5(new File(path))); }
public static String getMD5(File file) throws IOException { MessageDigest messageDigest = null; try { messageDigest = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } InputStream inputStream = new FileInputStream(file); byte[] buffer = new byte[4096]; int numRead; while ((numRead = inputStream.read(buffer)) > 0) { if (messageDigest != null) { messageDigest.update(buffer, 0, numRead); } else { throw new IOException("MessageDigest is NULL!"); } } inputStream.close(); if (messageDigest != null) { byte[] bytes = messageDigest.digest(); return bytesToHex(bytes); } else { throw new IOException("MessageDigest is NULL!"); } }
HashTool { public static String getMD5(File file) throws IOException { MessageDigest messageDigest = null; try { messageDigest = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } InputStream inputStream = new FileInputStream(file); byte[] buffer = new byte[4096]; int numRead; while ((numRead = inputStream.read(buffer)) > 0) { if (messageDigest != null) { messageDigest.update(buffer, 0, numRead); } else { throw new IOException("MessageDigest is NULL!"); } } inputStream.close(); if (messageDigest != null) { byte[] bytes = messageDigest.digest(); return bytesToHex(bytes); } else { throw new IOException("MessageDigest is NULL!"); } } }
HashTool { public static String getMD5(File file) throws IOException { MessageDigest messageDigest = null; try { messageDigest = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } InputStream inputStream = new FileInputStream(file); byte[] buffer = new byte[4096]; int numRead; while ((numRead = inputStream.read(buffer)) > 0) { if (messageDigest != null) { messageDigest.update(buffer, 0, numRead); } else { throw new IOException("MessageDigest is NULL!"); } } inputStream.close(); if (messageDigest != null) { byte[] bytes = messageDigest.digest(); return bytesToHex(bytes); } else { throw new IOException("MessageDigest is NULL!"); } }  }
HashTool { public static String getMD5(File file) throws IOException { MessageDigest messageDigest = null; try { messageDigest = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } InputStream inputStream = new FileInputStream(file); byte[] buffer = new byte[4096]; int numRead; while ((numRead = inputStream.read(buffer)) > 0) { if (messageDigest != null) { messageDigest.update(buffer, 0, numRead); } else { throw new IOException("MessageDigest is NULL!"); } } inputStream.close(); if (messageDigest != null) { byte[] bytes = messageDigest.digest(); return bytesToHex(bytes); } else { throw new IOException("MessageDigest is NULL!"); } }  static String getMD5(File file); static String getSHA256(File file); static String getMD5(byte[] aData); static String getSHA256(byte[] aData); static String hex2Str(byte[] data); }
HashTool { public static String getMD5(File file) throws IOException { MessageDigest messageDigest = null; try { messageDigest = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } InputStream inputStream = new FileInputStream(file); byte[] buffer = new byte[4096]; int numRead; while ((numRead = inputStream.read(buffer)) > 0) { if (messageDigest != null) { messageDigest.update(buffer, 0, numRead); } else { throw new IOException("MessageDigest is NULL!"); } } inputStream.close(); if (messageDigest != null) { byte[] bytes = messageDigest.digest(); return bytesToHex(bytes); } else { throw new IOException("MessageDigest is NULL!"); } }  static String getMD5(File file); static String getSHA256(File file); static String getMD5(byte[] aData); static String getSHA256(byte[] aData); static String hex2Str(byte[] data);  }