簡體   English   中英

如何給java中的Zip文件夾保護密碼?

[英]how to give the password protection to Zip folder in java?

我需要通過java為Zip文件夾設置密碼保護,而不是為zip文件夾文件。 沒有密碼我不應該打開Zip文件夾。

這是我從谷歌找到的代碼。

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

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

我所知道的唯一免費圖書館是winzipaes 它有一個Apache許可證。

Google Code項目頁面=> https://code.google.com/p/winzipaes/

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM