Java tutorial
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { public static byte[] getFileSHA1(String path) throws IOException { File file = new File(path); FileInputStream in = new FileInputStream(file); MessageDigest messagedigest; try { messagedigest = MessageDigest.getInstance("SHA-1"); byte[] buffer = new byte[1024 * 64]; int len; while ((len = in.read(buffer)) > 0) { messagedigest.update(buffer, 0, len); } return messagedigest.digest(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (OutOfMemoryError e) { e.printStackTrace(); throw e; } finally { in.close(); } return null; } }