MD5加密文件

这个可以直接使用哦

public class MD5Test {
	 
    public static String getFile(File file) {  
        if (!file.exists() || !file.isFile()) {  
            return null;  
        }  
        MessageDigest digest = null;  
        FileInputStream in = null;  
        byte buffer[] = new byte[1024];  
        int length;  
        try {  
            digest = MessageDigest.getInstance("MD5");  
            in = new FileInputStream(file);  
            while ((length = in.read(buffer, 0, 1024)) != -1) {  
                digest.update(buffer, 0, length);  
            }  
            in.close();  
        } catch (Exception e) {  
            e.printStackTrace();   
        }  
        BigInteger bigInt = new BigInteger(1, digest.digest());  
        return bigInt.toString(16); 
    }   
}


你可能感兴趣的:(Java)