fix:添加获取文件md5
This commit is contained in:
parent
79ac87c5ed
commit
dbb97bf20d
@ -3,12 +3,14 @@ package cn.axzo.oss.common.utils;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Objects;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.codec.binary.Hex;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
|
||||
/**
|
||||
* @Author admin
|
||||
@ -74,4 +76,21 @@ public class Utility {
|
||||
}
|
||||
return content;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件的MD5值
|
||||
* @param bytes
|
||||
* @return
|
||||
*/
|
||||
public static String getMd5(byte [] bytes) {
|
||||
try {
|
||||
MessageDigest md5 = MessageDigest.getInstance("MD5");
|
||||
md5.reset();
|
||||
md5.update(bytes);
|
||||
return Hex.encodeHexString(md5.digest());
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
log.warn("getMd5 fail = {}",e.getMessage());
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user