Masher a file : MessageDigest « Security « Java Tutorial






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

import sun.misc.BASE64Encoder;

public class MainClass {
  public static void main(String[] args) throws Exception {
    if (args.length != 1) {
      System.out.println("Usage: Masher filename");
      return;
    }
    MessageDigest md = MessageDigest.getInstance("MD5");
    FileInputStream in = new FileInputStream(args[0]);
    byte[] buffer = new byte[8192];
    int length;
    while ((length = in.read(buffer)) != -1)
      md.update(buffer, 0, length);
    byte[] raw = md.digest();
    BASE64Encoder encoder = new BASE64Encoder();
    String base64 = encoder.encode(raw);
    System.out.println(base64);
  }
}








36.27.MessageDigest
36.27.1.Message Digest Demo
36.27.2.Digest Stream
36.27.3.Make SHA Message
36.27.4.Make SHA Message with update methods
36.27.5.Masher a file
36.27.6.extends MessageDigest
36.27.7.MD5 MessageDigest
36.27.8.Digest Input
36.27.9.Create an encrypted string for password
36.27.10.Cryptography Streams: URLDigest