get paid to paste

java-zip4j-tut-create-zip-with-pass-1

import net.lingala.zip4j.ZipFile;
import net.lingala.zip4j.exception.ZipException;
import net.lingala.zip4j.model.ZipParameters;
import net.lingala.zip4j.model.enums.EncryptionMethod;
import net.lingala.zip4j.model.enums.AesKeyStrength;
import java.io.File;
import java.io.IOException;

public class SampleClass{

  public static void main(String[] args)
                     throws ZipException,
                            IOException{
    ZipFile zip = null;
    
    try{
      ZipParameters zp = new ZipParameters();
      zp.setEncryptFiles(true);
      zp.setEncryptionMethod
      (EncryptionMethod.AES);
      zp.setAesKeyStrength
      (AesKeyStrength.KEY_STRENGTH_256);
      
      zip = new ZipFile("myzip.zip","password".toCharArray());
      zip.addFolder(new File("folder"), zp);
      zip.addFile(new File("img.jpg"));
    }
    finally{
      if(zip != null)
        zip.close();
    }
    
    System.out.println
    ("main thread end");
  }
}

Pasted: Nov 27, 2024, 10:50:38 am
Views: 6