|
@@ -72,7 +72,7 @@ public class FileUtil {
|
|
|
*/
|
|
*/
|
|
|
public static String getMulFileMD5(InputStream fileInputStream) {
|
|
public static String getMulFileMD5(InputStream fileInputStream) {
|
|
|
try {
|
|
try {
|
|
|
- MessageDigest MD5 = MessageDigest.getInstance("MD5");
|
|
|
|
|
|
|
+ MessageDigest MD5 = MessageDigest.getInstance("SHA-256");
|
|
|
byte[] buffer = new byte[8192];
|
|
byte[] buffer = new byte[8192];
|
|
|
int length;
|
|
int length;
|
|
|
while ((length = fileInputStream.read(buffer)) != -1) {
|
|
while ((length = fileInputStream.read(buffer)) != -1) {
|
|
@@ -92,4 +92,35 @@ public class FileUtil {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取一个文件的md5值(可处理大文件)
|
|
|
|
|
+ * @return md5 value
|
|
|
|
|
+ */
|
|
|
|
|
+ public static String getMulFileMD5(MultipartFile file) {
|
|
|
|
|
+ InputStream fileInputStream = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+// MessageDigest MD5 = MessageDigest.getInstance("MD5");
|
|
|
|
|
+ MessageDigest MD5 = MessageDigest.getInstance("SHA-256");
|
|
|
|
|
+ fileInputStream = file.getInputStream();
|
|
|
|
|
+ byte[] buffer = new byte[8192];
|
|
|
|
|
+ int length;
|
|
|
|
|
+ while ((length = fileInputStream.read(buffer)) != -1) {
|
|
|
|
|
+ MD5.update(buffer, 0, length);
|
|
|
|
|
+ }
|
|
|
|
|
+ return new String(Hex.encodeHex(MD5.digest())).substring(0,32);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ return null;
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (fileInputStream != null){
|
|
|
|
|
+ fileInputStream.close();
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|