|
@@ -376,6 +376,18 @@ public class FileSECUtils {
|
|
|
return fileName.substring(0, dotIndex);
|
|
|
}
|
|
|
|
|
|
+ public static String getFileNameWithoutExtensionWindows(String filePath) {
|
|
|
+ // 提取最后一段文件名
|
|
|
+ int lastSlashIndex = filePath.lastIndexOf('\\');
|
|
|
+ String fileName = (lastSlashIndex == -1) ? filePath : filePath.substring(lastSlashIndex + 1);
|
|
|
+
|
|
|
+ int dotIndex = fileName.lastIndexOf('.');
|
|
|
+ if (dotIndex == -1) {
|
|
|
+ return fileName;
|
|
|
+ }
|
|
|
+ return fileName.substring(0, dotIndex);
|
|
|
+ }
|
|
|
+
|
|
|
public static boolean isMediaFile(String fileType) {
|
|
|
if (fileType == null || fileType.isEmpty()) {
|
|
|
return false;
|
|
@@ -413,7 +425,7 @@ public class FileSECUtils {
|
|
|
try {
|
|
|
logger.info("--------------SEC附件加密 processFileWithSEC1 ----------------");
|
|
|
String filename = getFileNameWithoutExtension(path);
|
|
|
- String filetype = getFileType(filename);
|
|
|
+ String filetype = getFileType(path);
|
|
|
/**
|
|
|
* 判断是否是媒体文件,如果是媒体文件,则不进行处理
|
|
|
*/
|
|
@@ -422,9 +434,10 @@ public class FileSECUtils {
|
|
|
return "";
|
|
|
}
|
|
|
String filepath = System.getProperty("java.io.tmpdir") + "/" + filename;
|
|
|
+ //String filepath = System.getProperty("java.io.tmpdir") + "\\" + filename;
|
|
|
// 1. 将 InputStream 写入本地临时文件
|
|
|
tempFile = File.createTempFile(filepath,"."+filetype);
|
|
|
- logger.info("--------------SEC附件临时路径 "+filepath,"."+filetype+" ----------------");
|
|
|
+ logger.info("--------------SEC附件临时路径 " + filepath + "." + filetype + " ----------------");
|
|
|
tempFile.deleteOnExit(); // 确保 JVM 退出时删除临时文件
|
|
|
|
|
|
try (FileOutputStream fos = new FileOutputStream(tempFile)) {
|
|
@@ -435,14 +448,14 @@ public class FileSECUtils {
|
|
|
}
|
|
|
}
|
|
|
//返回临时文件输入流,不能使用的文件流
|
|
|
- InputStream tmpInputStream = new FileInputStream(tempFile);
|
|
|
+ //InputStream tmpInputStream = new FileInputStream(tempFile);
|
|
|
|
|
|
// 2. 调用是否加密接口方法
|
|
|
int isEncrypted = checkFileIsEncryptionRest(new FileInputStream(tempFile));
|
|
|
if (isEncrypted == -1) {
|
|
|
logger.info("--------------SEC附件检查,文件加密状态检查失败----------------");
|
|
|
return "";
|
|
|
- } else if (isEncrypted == 0) {
|
|
|
+ } else if (isEncrypted == 1) {
|
|
|
logger.info("--------------SEC附件检查,是明文无需解密----------------");
|
|
|
return "";
|
|
|
}
|
|
@@ -450,7 +463,7 @@ public class FileSECUtils {
|
|
|
// 3. 获取文件大小
|
|
|
long fileSize = tempFile.length();
|
|
|
|
|
|
- // 4. 调用解密方法
|
|
|
+ // 4. 调用加密方法
|
|
|
InputStream decryptedInputStream = encodeFileForSEC(fileSize, new FileInputStream(tempFile));
|
|
|
if (decryptedInputStream == null) {
|
|
|
logger.info("--------------SEC附件加密,文件解密失败----------------");
|
|
@@ -462,7 +475,7 @@ public class FileSECUtils {
|
|
|
logger.info("--------------SEC附件加密,无法删除临时文件----------------");
|
|
|
}
|
|
|
|
|
|
- String url = getDownloadUrl(filename, decryptedInputStream);
|
|
|
+ String url = getDownloadUrl(filename+"."+filetype, decryptedInputStream);
|
|
|
|
|
|
// 返回解密后的输入流
|
|
|
return url;
|