|
@@ -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;
|
|
|
+
|
|
|
|
|
|
tempFile = File.createTempFile(filepath,"."+filetype);
|
|
|
- logger.info("--------------SEC附件临时路径 "+filepath,"."+filetype+" ----------------");
|
|
|
+ logger.info("--------------SEC附件临时路径 " + filepath + "." + filetype + " ----------------");
|
|
|
tempFile.deleteOnExit();
|
|
|
|
|
|
try (FileOutputStream fos = new FileOutputStream(tempFile)) {
|
|
@@ -435,14 +448,14 @@ public class FileSECUtils {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- InputStream tmpInputStream = new FileInputStream(tempFile);
|
|
|
+
|
|
|
|
|
|
|
|
|
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 {
|
|
|
|
|
|
long fileSize = tempFile.length();
|
|
|
|
|
|
-
|
|
|
+
|
|
|
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;
|