Мне нужно создать ZIP-файл. Он должен быть защищен паролем. Я использую лингала банку. Вот мой ниже. Есть ли способ сделать это? Я даже попробовал zipoutstream, не мог найти способ добавить пароль.
@Component
public class FileZipUtils {
@Value("${candela.email.zip.folder}")
private String zipBaseDir;
@Value("${candela.email.zip.encryptionmethod:AES}")
private String encryptionMethod;
@Value("${candela.email.zip.encryptionstrength:KEY_STRENGTH_128}")
private String encryptionStrength;
private ZipParameters zipParameters;
@PostConstruct
private void initializeZipProperties() {
zipParameters = new ZipParameters();
zipParameters.setEncryptFiles(true);
zipParameters.setEncryptionMethod(EncryptionMethod.AES);
zipParameters.setAesKeyStrength(AesKeyStrength.KEY_STRENGTH_128);
}
/*
* Creates a zipfile in the zipBaseDir location
*/
public ZipFile createZipFile(String zipFileName,char[] password) {
return new ZipFile(zipBaseDir + "/" + zipFileName,password);
}
/**
* Adds attachment to Zip file
*/
public void addAttachementToZip(ZipFile zipFile, ByteArrayResource fileContentInBytes, String fileName)
throws IOException {
zipParameters.setFileNameInZip(fileName);
zipFile.addStream(fileContentInBytes.getInputStream(), zipParameters);
}
}