How to create encrypted(password protect) ZIP file in Boomi
Updated: Mar 9, 2022
Few months back, we had a requirement to create encrypted (password protected) zip file and email it to specific recipients. When working on the integration, we understood that Boomi currently don't support Zip Encryption with Password.
Upon more analysis, we learned about a third party library Zip4j which has comprehensive features for Zip encryption and could be used in Boomi integration.
We will go through the steps to understand how a Boomi Process can create a password protected zip file.
Download the Java library and add it to account libraries
Download the JAR from https://mvnrepository.com/artifact/net.lingala.zip4j/zip4j/2.9.1. You can also download from here
zip4j-2.9.1
.jar
Download JAR • 209KB
2. In the AtomSphere platform, Go to Settings --> Account Information and Set up --> Account Libraries. Upload the downloaded JAR file from your local folder to the platform.

Create a custom library component and deploy it to your environment
Create a custom library component and select "Custom Library Type" as 'Scripting"
Add the uploaded JAR file to the custom library component.
Create a packaged component and deploy it to your environment

Configuration Parameters
To create a zip file, the following three properties have to be configured. A process property component "ZipConfig" is used to configure these parameters in the Boomi process.
ZipPassword - The password to protect the zip file

ZipFileAbsolutePath - Zip Absolute Filename. Please specify a directory where Boomi runtime has access.
Example value: C:\\Projects\\Labs\\ZipEncryption\\ZipOutput\\ZipFile.zip

SrcFilesFolderPath - One or more files that have to be zipped together has to be placed in a specific folder. The zip4j custom script retrieves all the files in this folder and adds it to the zip file.
Example value: C:\\Projects\\Labs\\ZipEncryption\\FilesToAdd

The following three files are placed in the Source Folder to be added to the ZipFile.

Demo Boomi Process
Please see below the demo process.

A No-Data start shape and Try/catch as boilerplate code.
The "ZipConfiguration" sets key properties for the zip4j custom script to create a zip file successfully. All three properties configured in "ZipConfig" Process Property are assigned to a DPP as shown below.


Zip4j Encrypt Script
The custom script reads the files from the Source Files Folder Path and writes a zip file in the specified folder
import java.util.Properties;
import java.io.InputStream;
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.CompressionMethod;
import net.lingala.zip4j.model.enums.AesKeyStrength;
import net.lingala.zip4j.model.FileHeader;
import com.boomi.execution.ExecutionUtil;
import java.io.*;
logger = ExecutionUtil.getBaseLogger();
// Get Dynamic Process Property and assign it to local variables
ZipPassword = ExecutionUtil.getDynamicProcessProperty("DPP_ZipPassword");
ZipFileAbsolutePath = ExecutionUtil.getDynamicProcessProperty("DPP_ZipAbsoluteFilename");
SrcFilesFolder = ExecutionUtil.getDynamicProcessProperty("DPP_SrcFilesFolderPath");
//Set ZipParameters
ZipParameters zipParameters = new ZipParameters();
zipParameters.setEncryptFiles(true);
zipParameters.setCompressionMethod(CompressionMethod.DEFLATE);
zipParameters.setEncryptionMethod(EncryptionMethod.AES);
zipParameters.setAesKeyStrength(AesKeyStrength.KEY_STRENGTH_256);
ZipFile zipFile = new ZipFile(ZipFileAbsolutePath,ZipPassword.toCharArray())
File folder = new File(SrcFilesFolder);
//List all files from the Source Files Folder
File[] listOfFiles = folder.listFiles();
List<File> filesToAdd = Arrays.asList(listOfFiles);
zipFile.addFiles(filesToAdd, zipParameters);
for( int i = 0; i < dataContext.getDataCount(); i++ ) {
InputStream is = dataContext.getStream(i);
Properties props = dataContext.getProperties(i);
dataContext.storeStream(is, props);
}
Final Output
Once the process completes successfully, the zip file will be created in the specified destination folder. When attempted to extract the zip file using WinZip, it will prompt for a password. When correct password is entered, the files will be extracted from zip file.


Conclusion
Zip4j is a convenient option to encrypt files till Boomi implements this as OOTB functionality in to the product. There is an idea already submitted and you can consider voting. (https://community.boomi.com/s/idea/0871W000000bsdRQAQ/detail)
In my next blog, I will write how to unzip/decrypt a zip file.
Please feel free to leave any questions/comments below.