我需要创建一个 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);
}
}
www说
跃然一笑
相关分类