feat: 在线编辑转换文件解密
This commit is contained in:
@@ -70,6 +70,36 @@ public class IntekeyUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static InputStream autoDecryptInputStreamFile(InputStream inputStream, String fileName) throws IOException {
|
||||
if (!ENABLE || inputStream == null) {
|
||||
return inputStream;
|
||||
}
|
||||
MultipartFile multipartFile = convertMultipart(inputStream, fileName);
|
||||
// 将文件解密
|
||||
try {
|
||||
return IntekeyUtils.decryptFile(DECRYPT_URL, DECRYPT_APP_CODE, DECRYPT_SECRET_KEY, null, multipartFile);
|
||||
} catch (Exception e) {
|
||||
log.error("文件解密失败,返回原文件");
|
||||
return inputStream;
|
||||
}
|
||||
}
|
||||
|
||||
public static MultipartFile convertMultipart(InputStream is, String fileName) throws IOException {
|
||||
// 假定文件名和内容类型已知
|
||||
String contentType = "application/octet-stream"; // 或其他类型
|
||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||
|
||||
int nRead;
|
||||
byte[] data = new byte[1024];
|
||||
while ((nRead = is.read(data, 0, data.length)) != -1) {
|
||||
buffer.write(data, 0, nRead);
|
||||
}
|
||||
buffer.flush();
|
||||
byte[] byteArray = buffer.toByteArray();
|
||||
|
||||
// 使用MockMultipartFile创建MultipartFile
|
||||
return new MockMultipartFile(fileName, fileName, contentType, byteArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密文件,返回InputStream,供excel使用
|
||||
|
||||
Reference in New Issue
Block a user