本文整理汇总了Java中net.lingala.zip4j.model.ZipParameters.setAesKeyStrength方法的典型用法代码示例。如果您正苦于以下问题:Java ZipParameters.setAesKeyStrength方法的具体用法?Java ZipParameters.setAesKeyStrength怎么用?Java ZipParameters.setAesKeyStrength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.lingala.zip4j.model.ZipParameters
的用法示例。
在下文中一共展示了ZipParameters.setAesKeyStrength方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: zip
import net.lingala.zip4j.model.ZipParameters; //导入方法依赖的package包/类
public static void zip(String targetPath, String destinationFilePath, String password) {
try {
ZipParameters parameters = new ZipParameters();
parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
if (password.length() > 0) {
parameters.setEncryptFiles(true);
parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_AES);
parameters.setAesKeyStrength(Zip4jConstants.AES_STRENGTH_256);
parameters.setPassword(password);
}
ZipFile zipFile = new ZipFile(destinationFilePath);
File targetFile = new File(targetPath);
if (targetFile.isFile()) {
zipFile.addFile(targetFile, parameters);
} else if (targetFile.isDirectory()) {
zipFile.addFolder(targetFile, parameters);
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例2: compress
import net.lingala.zip4j.model.ZipParameters; //导入方法依赖的package包/类
/**
* Compress.
*
* @param fileName
* the file name
* @param compressedFileName
* the compressed file name
* @param password
* the password
*/
public static void compress(String fileName, String compressedFileName, String password) {
try {
ZipParameters zipParameters = new ZipParameters();
zipParameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
zipParameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_ULTRA);
if (password != null) {
zipParameters.setEncryptFiles(true);
zipParameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_AES);
zipParameters.setAesKeyStrength(Zip4jConstants.AES_STRENGTH_256);
zipParameters.setPassword(password);
}
String destinationZipFilePath = compressedFileName;
ZipFile zipFile = new ZipFile(destinationZipFilePath);
zipFile.addFile(new File(fileName), zipParameters);
} catch (ZipException e) {
JKExceptionUtil.handle(e);
}
}
示例3: checkParameters
import net.lingala.zip4j.model.ZipParameters; //导入方法依赖的package包/类
private void checkParameters(ZipParameters parameters) throws ZipException {
if (parameters == null) {
throw new ZipException("cannot validate zip parameters");
}
if ((parameters.getCompressionMethod() != Zip4jConstants.COMP_STORE) &&
parameters.getCompressionMethod() != Zip4jConstants.COMP_DEFLATE) {
throw new ZipException("unsupported compression type");
}
if (parameters.getCompressionMethod() == Zip4jConstants.COMP_DEFLATE) {
if (parameters.getCompressionLevel() < 0 && parameters.getCompressionLevel() > 9) {
throw new ZipException("invalid compression level. compression level dor deflate should be in the range of 0-9");
}
}
if (parameters.isEncryptFiles()) {
if (parameters.getEncryptionMethod() != Zip4jConstants.ENC_METHOD_STANDARD &&
parameters.getEncryptionMethod() != Zip4jConstants.ENC_METHOD_AES) {
throw new ZipException("unsupported encryption method");
}
if (parameters.getPassword() == null || parameters.getPassword().length <= 0) {
throw new ZipException("input password is empty or null");
}
} else {
parameters.setAesKeyStrength(-1);
parameters.setEncryptionMethod(-1);
}
}
示例4: CompressTask
import net.lingala.zip4j.model.ZipParameters; //导入方法依赖的package包/类
public CompressTask(String destination, String source) {
this.destination = destination;
this.source = source;
parameters = new ZipParameters();
parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_AES);
parameters.setAesKeyStrength(Zip4jConstants.AES_STRENGTH_256);
parameters.setPassword("123");
timer = new Timer();
}
示例5: VideoWriter
import net.lingala.zip4j.model.ZipParameters; //导入方法依赖的package包/类
public VideoWriter( VideoInput _vi )
{
vi = _vi;
DVRLoader.getExecutor().execute( this );
parameters = new ZipParameters();
parameters.setCompressionMethod( Zip4jConstants.COMP_DEFLATE );
parameters.setCompressionLevel( Zip4jConstants.DEFLATE_LEVEL_NORMAL );
parameters.setEncryptFiles( true );
parameters.setEncryptionMethod( Zip4jConstants.ENC_METHOD_AES );
parameters.setAesKeyStrength( Zip4jConstants.AES_STRENGTH_256 );
parameters.setPassword( "OpenSpaceDVR2014" ); // Generate a private key for each DVR install. Installation ID maybe?
}
示例6: zip
import net.lingala.zip4j.model.ZipParameters; //导入方法依赖的package包/类
/**
* 使用给定密码压缩指定文件或文件夹到指定位置.
* @param srcFiles 要压缩的文件或文件夹File
* @param destFile 压缩文件存放File
* @param charset 编码方式
* @param passwd 密码
* @param compressionMethod 压缩方式【Zip4jConstants类参数】
* @param compressionLevel 压缩级别【Zip4jConstants类参数】
* @param encryptionMethod 加密方式【Zip4jConstants类参数】
* @throws ZipException
*/
private static void zip(File[] srcFiles,File destFile, String charset,
String passwd, int compressionMethod, int compressionLevel,
int encryptionMethod) throws ZipException {
//创建目标文件父级目录
FastFile.createParentDirectory(destFile);
ZipParameters parameters = new ZipParameters();
parameters.setCompressionMethod(compressionMethod); // 压缩方式
parameters.setCompressionLevel(compressionLevel); // 压缩级别
if (StringUtils.isNotBlank(passwd)) {
parameters.setEncryptFiles(true);
parameters.setEncryptionMethod(encryptionMethod); // 加密方式
if(encryptionMethod==Zip4jConstants.ENC_METHOD_AES){//如果加密方式为AES
parameters.setAesKeyStrength(Zip4jConstants.AES_STRENGTH_256);
}
parameters.setPassword(passwd.toCharArray());
}
ZipFile zipFile = new ZipFile(destFile);
zipFile.setFileNameCharset(charset);
for(File srcFile : srcFiles){
if (srcFile.isDirectory()) {
zipFile.addFolder(srcFile, parameters);
} else {
zipFile.addFile(srcFile, parameters);
}
}
}
示例7: example4
import net.lingala.zip4j.model.ZipParameters; //导入方法依赖的package包/类
/**
* 示例4 创建加密压缩包
*/
@Test
public void example4(){
try {
ZipFile zipFile = new ZipFile("src/main/resources/AddFilesWithAESZipEncryption.zip");
ArrayList<File> filesToAdd = new ArrayList<File>();
filesToAdd.add(new File("src/main/resources/sample.txt"));
filesToAdd.add(new File("src/main/resources/zip4j.txt"));
filesToAdd.add(new File("src/main/resources/zip4j-1.3.2.jar"));
ZipParameters parameters = new ZipParameters();
parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
parameters.setEncryptFiles(true);
parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_AES);
parameters.setAesKeyStrength(Zip4jConstants.AES_STRENGTH_256);
parameters.setPassword("123456");
zipFile.addFiles(filesToAdd, parameters);
} catch (ZipException e) {
e.printStackTrace();
}
}
示例8: ZipInputStream
import net.lingala.zip4j.model.ZipParameters; //导入方法依赖的package包/类
public ZipInputStream(InputStream in, String fileName, String pass, String encyptionMethod) throws ZipException {
super(in);
zipParameters = new ZipParameters();
zipParameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
zipParameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
zipParameters.setEncryptFiles(true);
String encParts[] = encyptionMethod.split("-");
if( encParts[0].equals("AES")) {
zipParameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_AES);
if (encParts[1].equals("128")) {
Log.d(TAG, "Encryption AES Strength 128-bit");
zipParameters.setAesKeyStrength(Zip4jConstants.AES_STRENGTH_128);
} else {
Log.d(TAG, "Encryption AES Strength 256-bit");
zipParameters.setAesKeyStrength(Zip4jConstants.AES_STRENGTH_256);
}
} else {
zipParameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_STANDARD);
Log.d(TAG, "Standard Encryption");
}
// TODO: If password not set, don't run backup?
zipParameters.setPassword(pass);
// parameters.setSourceExternalStream(true);
// parameters.setFileNameInZip(mediaFileName);
byteOutputStream = new ByteArrayOutputStream(bufferSize);
zipOutputStream = new ZipOutputStream(byteOutputStream);
zipOutputStream.putNextEntry(new File(fileName), zipParameters);
zipOutputStreamFinished = false;
byteArraySize = 0;
Log.d(TAG,"New zip file: "+fileName);
}
示例9: compressZipAddFile
import net.lingala.zip4j.model.ZipParameters; //导入方法依赖的package包/类
public void compressZipAddFile(String fileName, String password,
Boolean encrypt) throws ZipException {
ZipParameters parameters = new ZipParameters();
parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
parameters.setPassword(password);
parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_AES);
parameters.setAesKeyStrength(Zip4jConstants.AES_STRENGTH_256);
parameters.setEncryptFiles(encrypt);
zipFile.addFile(new File(fileName), parameters);
}
示例10: compressZipAddFolder
import net.lingala.zip4j.model.ZipParameters; //导入方法依赖的package包/类
public void compressZipAddFolder(String compressFolder, String password,
Boolean encrypt) throws ZipException {
ZipParameters parameters = new ZipParameters();
parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
parameters.setPassword(password);
parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_AES);
parameters.setAesKeyStrength(Zip4jConstants.AES_STRENGTH_256);
parameters.setEncryptFiles(encrypt);
zipFile.addFolder(compressFolder, parameters);
}
示例11: compressZipFromFolder
import net.lingala.zip4j.model.ZipParameters; //导入方法依赖的package包/类
public void compressZipFromFolder(String compressFolder, String password,
Boolean encrypt) throws ZipException {
ZipParameters parameters = new ZipParameters();
parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
parameters.setPassword(password);
parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_AES);
parameters.setAesKeyStrength(Zip4jConstants.AES_STRENGTH_256);
parameters.setEncryptFiles(encrypt);
zipFile.createZipFileFromFolder(compressFolder, parameters, true,
10485760);
}
示例12: AddFilesWithAESEncryption
import net.lingala.zip4j.model.ZipParameters; //导入方法依赖的package包/类
public AddFilesWithAESEncryption() {
try {
// Initiate ZipFile object with the path/name of the zip file.
ZipFile zipFile = new ZipFile("c:\\ZipTest\\AddFilesWithAESZipEncryption.zip");
// Build the list of files to be added in the array list
// Objects of type File have to be added to the ArrayList
ArrayList filesToAdd = new ArrayList();
filesToAdd.add(new File("c:\\ZipTest\\sample.txt"));
filesToAdd.add(new File("c:\\ZipTest\\myvideo.avi"));
filesToAdd.add(new File("c:\\ZipTest\\mysong.mp3"));
// Initiate Zip Parameters which define various properties such
// as compression method, etc. More parameters are explained in other
// examples
ZipParameters parameters = new ZipParameters();
parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE); // set compression method to deflate compression
// Set the compression level. This value has to be in between 0 to 9
// Several predefined compression levels are available
// DEFLATE_LEVEL_FASTEST - Lowest compression level but higher speed of compression
// DEFLATE_LEVEL_FAST - Low compression level but higher speed of compression
// DEFLATE_LEVEL_NORMAL - Optimal balance between compression level/speed
// DEFLATE_LEVEL_MAXIMUM - High compression level with a compromise of speed
// DEFLATE_LEVEL_ULTRA - Highest compression level but low speed
parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
// Set the encryption flag to true
// If this is set to false, then the rest of encryption properties are ignored
parameters.setEncryptFiles(true);
// Set the encryption method to AES Zip Encryption
parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_AES);
// Set AES Key strength. Key strengths available for AES encryption are:
// AES_STRENGTH_128 - For both encryption and decryption
// AES_STRENGTH_192 - For decryption only
// AES_STRENGTH_256 - For both encryption and decryption
// Key strength 192 cannot be used for encryption. But if a zip file already has a
// file encrypted with key strength of 192, then Zip4j can decrypt this file
parameters.setAesKeyStrength(Zip4jConstants.AES_STRENGTH_256);
// Set password
parameters.setPassword("test123!");
// Now add files to the zip file
// Note: To add a single file, the method addFile can be used
// Note: If the zip file already exists and if this zip file is a split file
// then this method throws an exception as Zip Format Specification does not
// allow updating split zip files
zipFile.addFiles(filesToAdd, parameters);
} catch (ZipException e) {
e.printStackTrace();
}
}
示例13: getParams
import net.lingala.zip4j.model.ZipParameters; //导入方法依赖的package包/类
protected ZipParameters getParams(String password, String fileNameInZip, DeflateLevel defLevel) {
ZipParameters params = new ZipParameters();
{
int dl;
if (defLevel == null) {
dl = Zip4jConstants.DEFLATE_LEVEL_NORMAL;
} else {
switch (defLevel) {
case FASTEST:
dl = Zip4jConstants.DEFLATE_LEVEL_FASTEST;
break;
case FAST:
dl = Zip4jConstants.DEFLATE_LEVEL_FAST;
break;
case NORMAL:
dl = Zip4jConstants.DEFLATE_LEVEL_NORMAL;
break;
case MAXIMUM:
dl = Zip4jConstants.DEFLATE_LEVEL_MAXIMUM;
break;
case ULTRA:
dl = Zip4jConstants.DEFLATE_LEVEL_ULTRA;
break;
default:
throw new IllegalStateException();
}
}
params.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
params.setCompressionLevel(dl);
}
if (fileNameInZip != null) {
params.setSourceExternalStream(true);
params.setFileNameInZip(fileNameInZip);
}
if (password != null) {
params.setEncryptFiles(true);
params.setEncryptionMethod(Zip4jConstants.ENC_METHOD_AES);
params.setAesKeyStrength(Zip4jConstants.AES_STRENGTH_256);
params.setPassword(password);
}
return params;
}