How to Create an Encrypted ZIP file to Quarantine a Dangerous File

2 min readJun 25, 2022


So, you’ve identified an infected file in your system. What should you do now? When outright deletion isn’t an option, it’s best to quarantine that file as quickly as possible. To that end, compressing the file into a ZIP archive is a great idea, as it neutralizes the individual threat if the archive remains unzipped.

Thankfully, there’s an API for that. Our Zip Quarantine API will allow you to zip, encrypt and password protect an infected file. Further, it will allow you to select which encryption algorithm you’d like to use (default is AES-256), allowing an extra level control over your file. Below, I’ll walk you through how to structure a Zip Quarantine API call using ready-to-run code snippets in Java. All you’ll need is your input file and a Cloudmersive API key (which can be obtained easily by registering a free account on our website).

Let’s start off by installing with Maven. First, add a reference to the repository in pom.xml:


Next, let’s add one to the dependency in pom.xml:


Now installation is complete. Let’s now add in the import classes to the top of our file, and call the zip quarantine function:

// Import classes:
//import com.cloudmersive.client.invoker.ApiClient;
//import com.cloudmersive.client.invoker.ApiException;
//import com.cloudmersive.client.invoker.Configuration;
//import com.cloudmersive.client.invoker.auth.*;
//import com.cloudmersive.client.ZipArchiveApi;
ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: Apikey
ApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");
Apikey.setApiKey("YOUR API KEY");
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
ZipArchiveApi apiInstance = new ZipArchiveApi();
String password = "password_example"; // String | Password to place on the Zip file; the longer the password, the more secure
File inputFile1 = new File("/path/to/inputfile"); // File | First input file to perform the operation on.
String encryptionAlgorithm = "encryptionAlgorithm_example"; // String | Encryption algorithm to use; possible values are AES-256 (recommended), AES-128, and PK-Zip (not recommended; legacy, weak encryption algorithm). Default is AES-256.
try {
Object result = apiInstance.zipArchiveZipCreateQuarantine(password, inputFile1, encryptionAlgorithm);
} catch (ApiException e) {
System.err.println("Exception when calling ZipArchiveApi#zipArchiveZipCreateQuarantine");

Within the code examples above, set “string password” equal to your desired password string. Below your file input, set “string encryptionAlgorithm” equal to whichever algorithm you wish to use.

Once you’ve completed these steps, you’re all done — no more coding required.




There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.