How to Decrypt and Unlock a ZIP file in Python

Cloudmersive
2 min readJan 7, 2023

--

Zip files are often used to securely share files across networks. Once that zip file reaches our network, we need to decrypt and unlock the file to access its contents, which we can accomplish manually or programmatically, depending on the volume of files in question.

Using the below API solution, you can easily decrypt and unlock incoming zip archives with only a few lines of ready-to-run Python code. This API has only two request parameters — including the zip file and its password — and once those details are entered, the file will be unzipped, revealing its protected contents.

To take advantage of this API, first run the below command to install the Python SDK:

pip install cloudmersive-convert-api-client

After that’s done, simply include the remaining code (beginning with the imports):

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

# 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))
input_file = '/path/to/inputfile' # file | Input file to perform the operation on.
zip_password = 'zip_password_example' # str | Required; Password for the input archive

try:
# Decrypt and remove password protection on a zip file
api_response = api_instance.zip_archive_zip_decrypt(input_file, zip_password)
pprint(api_response)
except ApiException as e:
print("Exception when calling ZipArchiveApi->zip_archive_zip_decrypt: %s\n" % e)

To complete your API call, all that’s left is to provide a valid Cloudmersive API key, which you can get by registering a free account on our website (free-tier API keys supply a limit of 800 API calls per month with zero commitments).

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet