How to Decrypt a Password-Protected ZIP File in C/C++
Encrypted ZIP files are a safe and efficient way to share large amounts of information electronically. However, if you are repeatedly accessing specific ZIP files, the encryption can become an inconvenience. In this brief tutorial, we will demonstrate how to use an API in C/C++ to decrypt a password-protected ZIP file without any trouble, enabling easier access going forward.
First, we will install libcurl into our C/C++ project:
libcurl/7.75.0
Once the installation is complete, we will call the function by inputting the target file, file password, and API key into the following code:
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_URL, "https://api.cloudmersive.com/convert/archive/zip/decrypt");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "zipPassword: <string>");
headers = curl_slist_append(headers, "Content-Type: multipart/form-data");
headers = curl_slist_append(headers, "Apikey: YOUR-API-KEY-HERE");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_mime *mime;
curl_mimepart *part;
mime = curl_mime_init(curl);
part = curl_mime_addpart(mime);
curl_mime_name(part, "inputFile");
curl_mime_filedata(part, "/path/to/file");
curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
res = curl_easy_perform(curl);
curl_mime_free(mime);
}
curl_easy_cleanup(curl);
And we’re done! If you need to obtain an API key, you can do so by visiting the Cloudmersive website and registering for a free account; this will provide access to 800 monthly calls across all our APIs.