How to Compress Files to an Encrypted & Password-Protected Zip Archive using Python

Automatically zipping files streamlines the process of sending multiple large files to an end destination. Encrypting and password-protecting those files ensures the security of those files in storage, guaranteeing they can only be viewed by users with access to the password in question. Our Zip Encrypt API provides a service which consolidates both steps into one, allowing compression of up to 10 files at a time with the option to elect which encryption algorithm is used. You can simply enter your desired password into the relevant parameter during the configuration process and share that password with whomever the file is intended for. Let’s take a look at how to structure your API call using Python code examples provided below.

For starters, let’s install the Python SDK using the following command:

pip install cloudmersive-convert-api-client

Then let’s add in the imports right after that:

from __future__ import print_function
import time
import cloudmersive_convert_api_client
from cloudmersive_convert_api_client.rest import ApiException
from pprint import pprint

Last but not least, let’s include the API key authorization snippet (you can get an API key by registering a free account on our website) and complete the process by calling the function:

# Configure API key authorization: Apikey
configuration = cloudmersive_convert_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'
# create an instance of the API class
api_instance = cloudmersive_convert_api_client.ZipArchiveApi(cloudmersive_convert_api_client.ApiClient(configuration))
password = 'password_example' # str | Password to place on the Zip file; the longer the password, the more secure
input_file1 = '/path/to/inputfile' # file | First input file to perform the operation on.
encryption_algorithm = 'encryption_algorithm_example' # str | 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. (optional)
input_file2 = '/path/to/inputfile' # file | Second input file to perform the operation on. (optional)
input_file3 = '/path/to/inputfile' # file | Third input file to perform the operation on. (optional)
input_file4 = '/path/to/inputfile' # file | Fourth input file to perform the operation on. (optional)
input_file5 = '/path/to/inputfile' # file | Fifth input file to perform the operation on. (optional)
input_file6 = '/path/to/inputfile' # file | Sixth input file to perform the operation on. (optional)
input_file7 = '/path/to/inputfile' # file | Seventh input file to perform the operation on. (optional)
input_file8 = '/path/to/inputfile' # file | Eighth input file to perform the operation on. (optional)
input_file9 = '/path/to/inputfile' # file | Ninth input file to perform the operation on. (optional)
input_file10 = '/path/to/inputfile' # file | Tenth input file to perform the operation on. (optional)
try:
# Compress files to create a new, encrypted and password-protected zip archive
api_response = api_instance.zip_archive_zip_create_encrypted(password, input_file1, encryption_algorithm=encryption_algorithm, input_file2=input_file2, input_file3=input_file3, input_file4=input_file4, input_file5=input_file5, input_file6=input_file6, input_file7=input_file7, input_file8=input_file8, input_file9=input_file9, input_file10=input_file10)
pprint(api_response)
except ApiException as e:
print("Exception when calling ZipArchiveApi->zip_archive_zip_create_encrypted: %s\n" % e)

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Cloudmersive

Cloudmersive

437 Followers

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