I am using libzippp to compress/decompress data.
When trying to decompress an archive that is encrypted (using 7z, ZipCrypto
or AES-256
does not matter), the function ZipEntry::readContent()
returns -25
every time.
According to the comments inside the code, this is supposed to mean that zip_fopen_index()
has failed, but clarifies nothing further. An idea was that since the archive is encrypted, zip_fopen_index_encrypted()
should be called instead of zip_fopen_index()
, but according to the documentation, zip_fopen_index_encrypted()
should be called automatically if the archive is encrypted.
Here is a small code snippet that I am using:
int main(int argc, char** argv) {
std::string destination = "C:\temp\temporary\";
std::string source = "C:\temp\test.zip";
libzippp::ZipArchive archive(source, "test");
bool open = archive.open(libzippp::ZipArchive::ReadOnly);
std::vector<libzippp::ZipEntry> entries = archive.getEntries();
std::vector<libzippp::ZipEntry>::iterator it;
libzippp::ZipEntry entry;
std::string folder;
std::string target;
for (it = entries.begin(); it != entries.end(); ++it)
{
entry = *it;
if (entry.isFile())
{
folder = destination.data() + std::filesystem::path(entry.getName()).parent_path().string();
target = folder + "\" + std::filesystem::path(entry.getName()).filename().string();
/* Create directory if it does not exist */
if (!std::filesystem::exists(folder))
std::filesystem::create_directories(folder);
std::string testString = entry.readAsText();
std::ofstream stream(target, std::ios::out | std::ios::binary);
int returnCode = entry.readContent(stream);
stream.close();
}
}
archive.close();
return 0;
}
returnCode
will be set to -25
for each entry (only) if the archive is encrypted.
The strings destination
, source
as well as the password passed to the ZipArchive
are setup for my example and will have to be adjusted.