Created
November 7, 2010 19:34
-
-
Save andrerocker/666344 to your computer and use it in GitHub Desktop.
Gerando md5sum de um arquivo utilizando API do Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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