How to Decrypt and Remove Password Protection on a Zip File using Java
If your application is providing access to password-protected zip files, it’s super convenient to provide a service for decrypting and removing that same protection on the client side. To do so efficiently, you can take advantage of our ZIP Decryption API. This API only requires the input file & the password for that file, so it’s extremely simple to set up and use as a service within your app. Below, we’ll walk through structuring an API call using ready-to-run code snippets provided in Java.
Let’s first install the Java SDK with Maven. Add a reference to the repository in pom.xml:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Then add a reference to the dependency in pom.xml:
<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v4.25</version>
</dependency>
</dependencies>
Once installation is complete, you can structure your API call using the below code examples. Before doing so, ensure you have the following parameters ready:
- Your input Zip file for the operation
- Your Zip file password
- Your Cloudmersive API key (you can get one by registering a free account on our website, www.cloudmersive.com)
// 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)
//Apikey.setApiKeyPrefix("Token");ZipArchiveApi apiInstance = new ZipArchiveApi();
File inputFile = new File("/path/to/inputfile"); // File | Input file to perform the operation on.
String zipPassword = "zipPassword_example"; // String | Required; Password for the input archive
try {
Object result = apiInstance.zipArchiveZipDecrypt(inputFile, zipPassword);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling ZipArchiveApi#zipArchiveZipDecrypt");
e.printStackTrace();
}