获取数据的md5值版权声明

原创
小哥 3年前 (2022-10-27) 阅读数 82 #大杂烩

public class MD5Utils {

public static void main(String[] args) throws Exception{
    File file = new File("D:\\msdia80.dll");
    String md5 = MD5Utils.getMD5(new FileInputStream(file));
    System.out.println(md5);
}

/**
 * 把文件拿来。MD5值
 */
public static String getMD5(InputStream in) {
    MessageDigest digest = null;
    byte buffer[] = new byte[1024 * 1024];
    int len;

    try {
        digest = MessageDigest.getInstance("MD5");
        while ((len = in.read(buffer, 0, 1024 * 1024)) != -1) {
            digest.update(buffer, 0, len);
        }
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
        throw new SunawException("把文件拿来。MD5错误");
    } catch (IOException e) {
        e.printStackTrace();
        throw new SunawException("把文件拿来。MD5错误");
    }
    BigInteger bigInt = new BigInteger(1, digest.digest());
    return bigInt.toString(16);
}

}

版权声明

所有资源都来源于爬虫采集,如有侵权请联系我们,我们将立即删除