3

I need to set password protection for Zip folder via java, not for zip folder files. Without password i should not be able to open the Zip folder.

This is the code i found from google.

 public static void encrypt(String key, InputStream is, OutputStream os)        
 throws Throwable {encryptOrDecrypt(key, Cipher.ENCRYPT_MODE, is, os);                             
}
Nesh
  • 134
  • 9
Sriram S
  • 533
  • 3
  • 26

2 Answers2

5

Done using winzipaes1.0.1.jar...

Sample Code...

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
  • 2,056
  • 3
  • 20
  • 31
  • friend,@ CoderNeji i need protection for zip folder only, no need of files in the zip folder – Sriram S Jul 29 '15 at 06:45
  • This will create a password protected zip file src.zip and on extraction it will give you src.txt... There is no password on txt file – CoderNeji Jul 29 '15 at 06:56
2

The only free library I know of that does this is winzipaes. It has an Apache licence.

Google Code project page => https://code.google.com/p/winzipaes/

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

kkaosninja
  • 1,301
  • 11
  • 21