Files
fys-Multi-tenant/fys-admin/src/main/java/com/fuyuanshen/web/util/FileHashUtil.java
DragonWenLong e2274bdf09 feat(web): 新增设备联调中心功能
- 新增设备联调中心相关控制器、服务、DTO和VO
- 实现设备列表查询、文件上传、操作视频添加、设备详情等功能
- 优化设备 logo 上传逻辑,支持批量上传
- 重构部分代码结构,提高可维护性
2025-09-11 11:07:58 +08:00

29 lines
817 B
Java

package com.fuyuanshen.web.util;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.io.InputStream;
import java.security.MessageDigest;
import java.util.HexFormat;
/**
* 文件哈希工具类
*/
public class FileHashUtil {
private static final String ALGORITHM = "SHA-256";
public static String hash(MultipartFile file) throws IOException {
MessageDigest digest = DigestUtils.getDigest(ALGORITHM);
try (InputStream in = file.getInputStream()) {
byte[] buf = new byte[8192];
int len;
while ((len = in.read(buf)) != -1) {
digest.update(buf, 0, len);
}
}
return HexFormat.of().formatHex(digest.digest());
}
}