From e26af85e049516e6ce2b082bc2bc90bf71643e95 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期五, 24 三月 2023 09:06:30 +0800 Subject: [PATCH] 1 --- src/main/java/com/lf/server/helper/Zip4jHelper.java | 27 +++++++++++++++++++-------- 1 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/lf/server/helper/Zip4jHelper.java b/src/main/java/com/lf/server/helper/Zip4jHelper.java index 57a6ebb..f9ed14b 100644 --- a/src/main/java/com/lf/server/helper/Zip4jHelper.java +++ b/src/main/java/com/lf/server/helper/Zip4jHelper.java @@ -41,7 +41,7 @@ f.delete(); } - ZipParameters params = getZipParams(); + ZipParameters params = getZipParams(!StringHelper.isEmpty(pwd)); // 瑕佹墦鍖呯殑鏂囦欢鎴栨枃浠跺す File currentFile = new File(sourcePath); @@ -84,23 +84,34 @@ /** * 鑾峰彇ZipParameters */ - public static ZipParameters getZipParams() { + public static ZipParameters getZipParams(boolean flag) { // 璁剧疆鍘嬬缉鏂囦欢鍙傛暟 ZipParameters params = new ZipParameters(); // 鍘嬬缉鏂瑰紡 params.setCompressionMethod(CompressionMethod.DEFLATE); // 鍘嬬缉绾у埆 params.setCompressionLevel(CompressionLevel.MAXIMUM); - // 鏄惁璁剧疆鍔犲瘑鏂囦欢 - params.setEncryptFiles(true); - // 璁剧疆AES鍔犲瘑寮哄害锛欿EY_STRENGTH_256 - params.setAesKeyStrength(AesKeyStrength.KEY_STRENGTH_128); - // 璁剧疆鍔犲瘑绠楁硶 - params.setEncryptionMethod(EncryptionMethod.AES); + + if (flag) { + // 鏄惁璁剧疆鍔犲瘑鏂囦欢 + params.setEncryptFiles(true); + // 璁剧疆AES鍔犲瘑寮哄害锛欿EY_STRENGTH_256 + params.setAesKeyStrength(AesKeyStrength.KEY_STRENGTH_128); + // 璁剧疆鍔犲瘑绠楁硶 + params.setEncryptionMethod(EncryptionMethod.AES); + } return params; } + /** + * 娣诲姞鏂囦欢鑷冲帇缂╁寘 + * + * @param zip ZipFile + * @param params ZipParameters + * @param file File + * @throws ZipException + */ private static void addZipFile(ZipFile zip, ZipParameters params, File file) throws ZipException { if (file.isDirectory()) { File[] files = file.listFiles(); -- Gitblit v1.9.3