Sri*_*m S 3 java encryption passwords zip password-protection
我需要通过Java为Zip文件夹设置密码保护,而不是为zip文件夹文件设置密码保护。没有密码,我将无法打开Zip文件夹。
这是我从Google找到的代码。
public static void encrypt(String key, InputStream is, OutputStream os)
throws Throwable {encryptOrDecrypt(key, Cipher.ENCRYPT_MODE, is, os);
}
Run Code Online (Sandbox Code Playgroud)
使用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();
}
}
Run Code Online (Sandbox Code Playgroud)