How to decrypt/unzip a password protected zip file in Boomi
- Alex James
- Mar 13, 2022
- 1 min read
Updated: Mar 1, 2024
Boomi OOTB currently doesn't support unzipping a password protected zip file. However, this can be accomplished using a third party library Zip4j which has comprehensive features for Zip encryption/decryption.
We will go through the steps to understand how a Boomi Process can extract files from a password protected zip file.
There are two ways how the ZipFile document can be passed as input to the Zip4j custom script. a) ZipFile present in a local disk location and the script can directly access the file from the source directory.
b) ZipFile document is passed as InputStream to the Zip4j script. Usually documents flow as streams of data from one shape to another in the process. If the ZipFile is retrieved from source application say SFTP folder or email attachment, then the document will be as a data stream and can be passed directly as InputStream to the Zip4j script.
However in both the approaches, the extracted files will be written to a local destination directory.
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
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

Approach 1: ZipFile present in a local directory and extracted files written to a local destination directory
Unzip Config Parameters: A process property is used to configure the following three properties as input parameters to the zip4j custom script.
AbsoulteZipfilename: Absolute Zipfilename (The Zip file should be present in a directory where Boomi runtime has access)
Sample value: C:\\Projects\\Labs\\DecryptZip\\ZipFile.zip
DestinationDirectory: Directory path where the extracted files will be written.
Sample value: C:\\Projects\\Labs\\DecryptZip\\extractedfiles\\
UnZipPassword: Password of the ZipFile

Boomi Process:

Set Properties Shape (Unzip Config)
Assign all the input parameters configured in the process property to a DPP so that it can be easily accessed inside the custom script.



Zip4j Custom Script
The below custom script is executed via the data process shape.
import java.util.Properties;
import java.io.InputStream;
import net.lingala.zip4j.ZipFile;
import com.boomi.execution.ExecutionUtil;
sourcezipfile = ExecutionUtil.getDynamicProcessProperty("DPP_SourceZipfile");
destination_directory = ExecutionUtil.getDynamicProcessProperty("DPP_Destination_Directory");
pwd = ExecutionUtil.getDynamicProcessProperty("DPP_ZipPassword");
new ZipFile(sourcezipfile, pwd.toCharArray()).extractAll(destination_directory);
for( int i = 0; i < dataContext.getDataCount(); i++ ) {
InputStream is = dataContext.getStream(i);
Properties props = dataContext.getProperties(i);
dataContext.storeStream(is, props);
}Approach 2: ZipFile document is passed as InputStream to the Zip4j script.
Unzip Config Parameters:
A process property is used to configure the following two properties as input parameters to the zip4j custom script. The two input parameters are the same as that of Approach 1 except AbsoulteZipfilename property is NOT used in this approach as the document is passed as InputStream inside the custom script.
DestinationDirectory: Directory path where the extracted files will be written.
Sample value: C:\\Projects\\Labs\\DecryptZip\\extractedfiles\\
UnZipPassword: Password of the ZipFile
Boomi Process:

1) Get Zip File:
The Zip File can be retrieved from any source application and the document can be passed as stream of data to the subsequent shape. To simulate this, a disk connector is used to pick the zip file from a local directory and the document will then flow to the custom script.
2) UnZip Config
Assign all the input parameters configured in the process property to a DPP so that it can be easily accessed inside the custom script. (Same as in approach 1)
3) Zip4j Script
The below custom script is executed via the data process shape.
import java.util.Properties;
import java.io.InputStream;
import net.lingala.zip4j.model.LocalFileHeader;
import net.lingala.zip4j.io.inputstream.ZipInputStream;
import java.io.File;
import com.boomi.execution.ExecutionUtil;
import java.io.*;
LocalFileHeader localFileHeader;
ZipPassword = ExecutionUtil.getDynamicProcessProperty("DPP_ZipPassword");
Destination_Directory = ExecutionUtil.getDynamicProcessProperty("DPP_Destination_Directory");
int readLen;
byte[] readBuffer = new byte[8192];
for( int i = 0; i < dataContext.getDataCount(); i++ ) {
InputStream is = dataContext.getStream(i);
Properties props = dataContext.getProperties(i);
ZipInputStream zipInputStream = new ZipInputStream(is, ZipPassword.toCharArray());
while ((localFileHeader = zipInputStream.getNextEntry()) != null) {
filename = Destination_Directory + localFileHeader.getFileName();
File extractedFile = new File(filename);
OutputStream outputStream = new FileOutputStream(filename);
while ((readLen = zipInputStream.read(readBuffer)) != -1) {
outputStream.write(readBuffer, 0, readLen);
}
outputStream.close();
}
dataContext.storeStream(is, props);
}Final Output
Once the process completes successfully, the extracted files will be placed in the configured destination directory.

Please feel free to comment if you have any questions/queries related to this script.



Have you tested Your Scipt??
it is throwing :-- unable to resolve class net.lingala.zip4j.ZipFile @ line 3, column 1. Error