Skip to content

Instantly share code, notes, and snippets.

@andrerocker
Created November 7, 2010 19:34
Show Gist options
  • Save andrerocker/666344 to your computer and use it in GitHub Desktop.
Save andrerocker/666344 to your computer and use it in GitHub Desktop.
Gerando md5sum de um arquivo utilizando API do Java
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.math.BigInteger;
import java.security.MessageDigest;
public class Util
{
public static String md5File(File file) throws Exception
{
BufferedInputStream input = new BufferedInputStream(new FileInputStream(file));
MessageDigest digest = MessageDigest.getInstance("MD5");
byte[] buffer = new byte[1024];
int len = 0;
while((len=input.read(buffer))>0)
digest.update(buffer, 0, len);
byte[] md5sum = digest.digest();
BigInteger sign = new BigInteger(1, md5sum);
return sign.toString(16);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment