【问题标题】:how to give the password protection to Zip folder in java?如何在java中为Zip文件夹提供密码保护?
【发布时间】:2015-10-19 21:23:33
【问题描述】:

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

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

 public static void encrypt(String key, InputStream is, OutputStream os)        
 throws Throwable {encryptOrDecrypt(key, Cipher.ENCRYPT_MODE, is, os);                             
}

【问题讨论】:

标签: java encryption passwords zip password-protection


【解决方案1】:

我所知道的唯一一个这样做的免费库是 winzipaes。它有一个 Apache 许可证。

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

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

【讨论】:

  • 但是那个罐子帮不了我..建议任何工作代码链接@kkaosninja
【解决方案2】:

使用 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();
   }
}

【讨论】:

  • 朋友,@ CoderNeji 我只需要保护 zip 文件夹,不需要 zip 文件夹中的文件
  • 这将创建一个受密码保护的 zip 文件 src.zip 并在提取时为您提供 src.txt... txt 文件上没有密码
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-05-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多