Decrypt a Password-Protected ZIP File in Ruby

Let’s face it, while encrypted ZIP files are an excellent way to secure information, they aren’t winning any file format popularity awards. If you download or receive an encrypted ZIP file that you need to switch to a more accessible format, we have a solution that can assist in making the process quick and painless. The following instructions will guide you through how to decrypt a ZIP file using our Decrypt PDF API in Ruby; both the input archive and password are required to complete the decryption.

To begin, we will add the Ruby client to our Gemfile:

gem 'cloudmersive-convert-api-client', '~> 2.1.6'

Next, we can call the API function by adding our inputs to the below code:

# load the gem
require 'cloudmersive-convert-api-client'
# setup authorization
CloudmersiveConvertApiClient.configure do |config|
# Configure API key authorization: Apikey
config.api_key['Apikey'] = 'YOUR API KEY'
# Uncomment the following line to set a prefix for the API key, e.g. 'Bearer' (defaults to nil)
#config.api_key_prefix['Apikey'] = 'Bearer'
api_instance = CloudmersiveConvertApiClient::ZipArchiveApi.newinput_file ='/path/to/inputfile') # File | Input file to perform the operation on.zip_password = 'zip_password_example' # String | Required; Password for the input archivebegin
#Decrypt and remove password protection on a zip file
result = api_instance.zip_archive_zip_decrypt(input_file, zip_password)
p result
rescue CloudmersiveConvertApiClient::ApiError => e
puts "Exception when calling ZipArchiveApi->zip_archive_zip_decrypt: #{e}"

This will ensure that documents that were downloaded online or received from an external partner can be opened without a password in the future.

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