对上传文件进行加密处理
This commit is contained in:
parent
02ac23df57
commit
85cafb7257
|
|
@ -744,7 +744,9 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
.setPrjDir(false);
|
||||
this.saveOrUpdate(newEdFileInfo);
|
||||
String fileDestPath = commonService.getFileSysPath(newEdFileInfo.getFilePath());
|
||||
fileSystemService.save(file.getInputStream(), fileDestPath);
|
||||
FileUtil.writeFromStream(file.getInputStream(), fileDestPath);
|
||||
EleCommonUtil.encryptFile(fileDestPath, SecureUtil.aes(password.getBytes()));
|
||||
fileSystemService.save(FileUtil.getInputStream(fileDestPath), fileDestPath);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
newEdFileInfo.setParentId(parentId)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.electromagnetic.industry.software.manage.service.serviceimpl;
|
|||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
|
@ -22,6 +23,7 @@ import com.electromagnetic.industry.software.manage.pojo.resp.FileSimpleInfoVO;
|
|||
import com.electromagnetic.industry.software.manage.service.EdFileRelationService;
|
||||
import com.electromagnetic.industry.software.manage.service.FileSystemService;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
|
@ -43,6 +45,8 @@ public class EdFileRelationServiceImpl extends ServiceImpl<EdFileRelationMapper,
|
|||
private CommonService commonService;
|
||||
@Resource
|
||||
private FileSystemService fileSystemService;
|
||||
@Value("${file.security.passwd}")
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 创建文件关系
|
||||
|
|
@ -230,7 +234,9 @@ public class EdFileRelationServiceImpl extends ServiceImpl<EdFileRelationMapper,
|
|||
.setPrjDir(false);
|
||||
edFileInfoService.saveOrUpdate(newEdFileInfo);
|
||||
String fileDestPath = commonService.getFileSysPath(newEdFileInfo.getFilePath());
|
||||
fileSystemService.save(file.getInputStream(), fileDestPath);
|
||||
FileUtil.writeFromStream(file.getInputStream(), fileDestPath);
|
||||
EleCommonUtil.encryptFile(fileDestPath, SecureUtil.aes(password.getBytes()));
|
||||
fileSystemService.save(FileUtil.getInputStream(fileDestPath), fileDestPath);
|
||||
|
||||
// 创建文件关系
|
||||
EdFileRelation relation = new EdFileRelation();
|
||||
|
|
|
|||
|
|
@ -1,7 +1,15 @@
|
|||
package com.electromagnetic.industry.software.common.util;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.symmetric.AES;
|
||||
import com.electromagnetic.industry.software.common.exception.BizException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.regex.Pattern;
|
||||
|
|
@ -16,6 +24,8 @@ public final class EleCommonUtil {
|
|||
// 编译正则表达式
|
||||
private static final Pattern pattern = Pattern.compile(PATTERN);
|
||||
|
||||
private static EleLog log = new EleLog(EleCommonUtil.class);
|
||||
|
||||
public static String getFileName(String fileFullName) {
|
||||
if (fileFullName == null) {
|
||||
return "";
|
||||
|
|
@ -52,4 +62,21 @@ public final class EleCommonUtil {
|
|||
return now.format(formatter);
|
||||
}
|
||||
|
||||
public static void encryptFile(String filePath, AES aes) {
|
||||
String tmpPath = filePath + ".tmp";
|
||||
try (
|
||||
InputStream inputStream = Files.newInputStream(Paths.get(filePath));
|
||||
OutputStream outputStream = Files.newOutputStream(Paths.get(tmpPath));
|
||||
) {
|
||||
aes.encrypt(inputStream, outputStream, true);
|
||||
} catch (Exception e) {
|
||||
String info = "文件加密失败";
|
||||
log.error(info, e);
|
||||
throw new BizException(-1, info);
|
||||
} finally {
|
||||
FileUtil.del(filePath);
|
||||
FileUtil.move(new File(tmpPath), new File(filePath), true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue