How to Encrypt and Password Protect a Zip File Automatically using Java

2 min readJun 30, 2022


Zipped files save a lot of time when it comes to sharing multiple large files across a network. Securing those files, however, is a different question entirely. To prevent unwanted viewership of the files within a particular Zip, you should encrypt and password protect your file. Thankfully, there’s an API for that: our Zip Encryption API will complete that process in one fell swoop. You can easily include this service in your application using the ready-to-run code examples provided below in Java to structure your API call.

Let’s begin Java SDK installation by first including a reference in the pom.xml repository:


Next, add one to the pom.xml dependency:


Now add the imports to the top of your file and call the API. Before doing so, however, ensure your parameters are ready. Those should include:

  1. Your input Zip file for the operation
  2. Your Cloudmersive API key (obtainable by visiting our website,, and registering a free account)
// 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();
ZipEncryptionAdvancedRequest encryptionRequest = new ZipEncryptionAdvancedRequest(); // ZipEncryptionAdvancedRequest | Encryption request
try {
Object result = apiInstance.zipArchiveZipEncryptAdvanced(encryptionRequest);
} catch (ApiException e) {
System.err.println("Exception when calling ZipArchiveApi#zipArchiveZipEncryptAdvanced");




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