feat: 通用文件上传解密方法
This commit is contained in:
@@ -261,6 +261,10 @@
|
|||||||
<groupId>p6spy</groupId>
|
<groupId>p6spy</groupId>
|
||||||
<artifactId>p6spy</artifactId>
|
<artifactId>p6spy</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-test</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@@ -6,6 +6,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.core.io.FileSystemResource;
|
import org.springframework.core.io.FileSystemResource;
|
||||||
import org.springframework.http.*;
|
import org.springframework.http.*;
|
||||||
|
import org.springframework.mock.web.MockMultipartFile;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.util.DigestUtils;
|
import org.springframework.util.DigestUtils;
|
||||||
import org.springframework.util.LinkedMultiValueMap;
|
import org.springframework.util.LinkedMultiValueMap;
|
||||||
@@ -33,23 +34,46 @@ public class IntekeyUtils {
|
|||||||
public void setEnable(boolean enable) {
|
public void setEnable(boolean enable) {
|
||||||
ENABLE = enable;
|
ENABLE = enable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Value("${download.decrypt.url}")
|
@Value("${download.decrypt.url}")
|
||||||
public void setDecryptUrl(String decryptUrl) {
|
public void setDecryptUrl(String decryptUrl) {
|
||||||
DECRYPT_URL = decryptUrl;
|
DECRYPT_URL = decryptUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Value("${download.decrypt.app_code}")
|
@Value("${download.decrypt.app_code}")
|
||||||
public void setDecryptAppCode(String decryptAppCode) {
|
public void setDecryptAppCode(String decryptAppCode) {
|
||||||
DECRYPT_APP_CODE = decryptAppCode;
|
DECRYPT_APP_CODE = decryptAppCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Value("${download.decrypt.secret_key}")
|
@Value("${download.decrypt.secret_key}")
|
||||||
public void setDecryptSecretKey(String decryptSecretKey) {
|
public void setDecryptSecretKey(String decryptSecretKey) {
|
||||||
DECRYPT_SECRET_KEY = decryptSecretKey;
|
DECRYPT_SECRET_KEY = decryptSecretKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static MultipartFile autoDecryptFile(MultipartFile file) {
|
||||||
|
if (!ENABLE || file == null) {
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 将文件解密
|
||||||
|
InputStream inputStream;
|
||||||
|
try {
|
||||||
|
inputStream = IntekeyUtils.decryptFile(DECRYPT_URL, DECRYPT_APP_CODE, DECRYPT_SECRET_KEY, null, file);
|
||||||
|
return new MockMultipartFile(
|
||||||
|
file.getName(),
|
||||||
|
file.getOriginalFilename(),
|
||||||
|
file.getContentType(),
|
||||||
|
inputStream);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("文件解密失败,返回原文件");
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 解密文件,返回InputStream,供excel使用
|
* 解密文件,返回InputStream,供excel使用
|
||||||
*
|
*
|
||||||
*
|
|
||||||
* @param url
|
* @param url
|
||||||
* @param multipartFile
|
* @param multipartFile
|
||||||
* @return
|
* @return
|
||||||
|
|||||||
Reference in New Issue
Block a user