Create a ZIP Archive to Quarantine an Infected File in Python
Quarantining files that have been identified as a threat is a key step in ensuring the rest of your assets remain secure. This quick tutorial will guide you through how you can use an API in Python to quarantine an infected file (or files) by creating an encrypted and password-protected ZIP archive.
Let’s begin the process by running this command to install the SDK:
pip install cloudmersive-convert-api-client
Next, we can call the function by inputting the dangerous file and API key into the following code:
from __future__ import print_function
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))
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)try:
# Create an encrypted zip file to quarantine a dangerous file
api_response = api_instance.zip_archive_zip_create_quarantine(password, input_file1, encryption_algorithm=encryption_algorithm)
except ApiException as e:
print("Exception when calling ZipArchiveApi->zip_archive_zip_create_quarantine: %s\n" % e)
And just like that, the process is complete! If you need to retrieve an API key, you can do so by registering for a free account on the Cloudmersive website; this provides 800 monthly calls across any of our APIs.