Create Encrypted and Unencrypted ZIP Archives in Java with Cloudmersive API

This guide shows Java developers how to use the Cloudmersive API to create both unencrypted and password‑protected ZIP archives, covering Maven setup, API key configuration, and complete code examples for handling up to ten files with optional AES‑256 encryption.

Programmer DD
Programmer DD
Programmer DD
Create Encrypted and Unencrypted ZIP Archives in Java with Cloudmersive API

ZIP files are ubiquitous for compressing and sharing data, and the Cloudmersive API lets Java developers create both unencrypted and encrypted ZIP archives programmatically.

First, add the Cloudmersive Maven repository and dependency to your pom.xml:

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>com.github.Cloudmersive</groupId>
        <artifactId>Cloudmersive.APIClient.Java</artifactId>
        <version>v3.90</version>
    </dependency>
</dependencies>

Configure the API client with your key (obtain a free key from Cloudmersive):

ApiClient defaultClient = Configuration.getDefaultApiClient();
ApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");
Apikey.setApiKey("YOUR API KEY");

Example 1 creates an unencrypted ZIP containing up to ten files:

ZipArchiveApi apiInstance = new ZipArchiveApi();
File inputFile1 = new File("/path/to/inputfile");
// ... define inputFile2 … inputFile10 similarly
try {
    byte[] result = apiInstance.zipArchiveZipCreate(
        inputFile1, inputFile2, inputFile3, inputFile4, inputFile5,
        inputFile6, inputFile7, inputFile8, inputFile9, inputFile10);
    System.out.println(result);
} catch (ApiException e) {
    System.err.println("Exception when calling ZipArchiveApi#zipArchiveZipCreate");
    e.printStackTrace();
}

Example 2 adds password protection and lets you choose an encryption algorithm (AES‑256 recommended):

ZipArchiveApi apiInstance = new ZipArchiveApi();
String password = "password_example";
String encryptionAlgorithm = "encryptionAlgorithm_example";
File inputFile1 = new File("/path/to/inputfile");
// ... define inputFile2 … inputFile10 similarly
try {
    byte[] result = apiInstance.zipArchiveZipCreateEncrypted(
        password, inputFile1, encryptionAlgorithm,
        inputFile2, inputFile3, inputFile4, inputFile5,
        inputFile6, inputFile7, inputFile8, inputFile9, inputFile10);
    System.out.println(result);
} catch (ApiException e) {
    System.err.println("Exception when calling ZipArchiveApi#zipArchiveZipCreateEncrypted");
    e.printStackTrace();
}

Use a strong password and keep it secure.

Encryption algorithm can be AES‑256 (recommended), AES‑128, or PK‑Zip (legacy, weak).

Run the code to obtain the desired ZIP file and share it easily.

Feel free to try it and leave comments or questions.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaAPIencryptionFile CompressionzipCloudmersive
Programmer DD
Written by

Programmer DD

A tinkering programmer and author of "Spring Cloud Microservices in Action"

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.