jinlin
2023-12-28 63447fec93e8e562833db30bc848884001b808c4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package com.zt.life.util;
 
public class ZipCipherUtil {
    /**
     * 对目录srcFile下的所有文件目录进行先压缩后加密,然后保存为destfile
     *
     * @param srcFile
     *            要操作的文件或文件夹
     * @param destfile
     *            压缩加密后存放的文件
     * @param keyStr
     *            密钥
     */
    public void encryptZip(String srcFile, String destfile, String keyStr) {
        try {
/*            File temp = new File(UUID.randomUUID().toString() + ".zip");
            temp.deleteOnExit();
            // 先压缩文件
            // new ZipUtil().zip(srcFile, temp.getAbsolutePath());
            cn.hutool.core.util.ZipUtil.zip(srcFile, temp.getAbsolutePath(), false);
            // 对文件加密
            // FileAESUtil.EncFile(temp.getAbsolutePath(), destfile);
            new CipherUtil().encrypt(temp.getAbsolutePath(), destfile, keyStr);
            temp.delete();*/
            cn.hutool.core.util.ZipUtil.zip(srcFile, destfile, false);
        } catch (Exception e) {
        }
    }
 
    /**
     * 对文件srcfile进行先解密后解压缩,然后解压缩到目录destfile下
     *
     * @param srcfile
     *            要解密和解压缩的文件名
     * @param destfile
     *            解压缩后的目录
     * @param keyStr
     *            密钥
     */
    public void decryptUnzip(String srcfile, String destfile, String keyStr) {
        try {
/*            File temp = new File(UUID.randomUUID().toString() + ".zip");
            temp.deleteOnExit();
            // 先对文件解密
            new CipherUtil().decrypt(srcfile, temp.getAbsolutePath(), keyStr);
            // FileAESUtil.DecFile(srcfile, temp.getAbsolutePath());
            // 解压缩
            // new ZipUtil().unZip(temp.getAbsolutePath(), destfile);
            cn.hutool.core.util.ZipUtil.unzip(temp.getAbsolutePath(), destfile);
            temp.delete();*/
            cn.hutool.core.util.ZipUtil.unzip(srcfile, destfile);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}