Use SHA1 : SHA1 Secure Hash Algorithm « Security « Java Tutorial






import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.security.DigestInputStream;
import java.security.MessageDigest;

public class MainClass {
  private static int BUFFER_SIZE = 32 * 1024;

  public static void main(String[] args) throws Exception {
    System.out.println("test.txt: " + md("test.txt"));
  }

  public static String md(String f) throws Exception {
    BufferedInputStream file = new BufferedInputStream(new FileInputStream(f));
    MessageDigest md = MessageDigest.getInstance("SHA-1");
    DigestInputStream in = new DigestInputStream(file, md);
    int i;
    byte[] buffer = new byte[BUFFER_SIZE];
    do {
      i = in.read(buffer, 0, BUFFER_SIZE);
    } while (i == BUFFER_SIZE);
    md = in.getMessageDigest();
    in.close();

    return new String(md.digest());
  }
}








36.42.SHA1 Secure Hash Algorithm
36.42.1.Basic IO example using SHA1
36.42.2.PSS parameter recovery and encoding
36.42.3.Use SHA1
36.42.4.Encrypt a password