代码之家  ›  专栏  ›  技术社区  ›  Sriram S

如何在java中为Zip文件夹提供密码保护?

  •  3
  • Sriram S  · 技术社区  · 9 年前

    我需要通过java为Zip文件夹设置密码保护,而不是为Zip文件夹文件设置密码保护。没有密码,我将无法打开Zip文件夹。

    这是我从谷歌找到的代码。

     public static void encrypt(String key, InputStream is, OutputStream os)        
     throws Throwable {encryptOrDecrypt(key, Cipher.ENCRYPT_MODE, is, os);                             
    }
    
    2 回复  |  直到 9 年前
        1
  •  5
  •   CoderNeji    9 年前

    使用winzipaes1.0.1.jar完成。。。

    示例代码。。。

    import java.io.File;
    import java.io.IOException;
    import de.idyl.winzipaes.AesZipFileEncrypter;
    import de.idyl.winzipaes.impl.AESEncrypterBC;
    
    public class Practice1Main {
    
    public static void main(String[]args) throws IOException{
    
    
        File aNewZipFile = new File("src.zip");
        File existingUnzippedFile = new File("src.txt");
    
        AESEncrypterBC encrypter = new AESEncrypterBC();
        encrypter.init("password", 0);  // The 0 is keySize, it is ignored for AESEncrypterBC
    
        AesZipFileEncrypter zipEncrypter = new AesZipFileEncrypter(aNewZipFile, encrypter);
    
        zipEncrypter.add(existingUnzippedFile, "src.txt", "password");
        zipEncrypter.close();
       }
    }
    
        2
  •  2
  •   wandering-geek    9 年前

    我所知道的唯一一个这样做的免费图书馆是 Winzipais(winzipais) 。它有Apache许可证。

    谷歌代码项目页面=> https://code.google.com/p/winzipaes/

    Maven Repo链接=> http://mvnrepository.com/artifact/de.idyl/winzipaes