I'm using libZip in my project, I success to create zip file output, but I'm having difficulty to set a password to a zip file.
I'm calling the zip_set_default_password fucntion and I'm getting the OK response, but when I'm trying to extract it didn't ask for a password.
Code sample:
int CompressWithPassword(const char * psFileContent, int iFileSize, const char * pcPassword)
{
zip_source *psZipSource = NULL;
zip_int64_t iIndex = 0;
int iError = EOK;
const char * pcZipOutputPath = "/home/user/Documents/myzip.zip";
// Open zip file.
m_psZip =
zip_open(pcZipOutputPath,
ZIP_CREATE /*Create the archive if it does not exist*/,
&iError);
// Zip opend ?
if(iError != ZIP_ER_OK)
{
Close();
return iError;
}
// Generate zip source content.
psZipSource =
zip_source_buffer(m_psZip,
psFileContent,
iFileSize,
0);
// Valid zip source ?
if(psZipSource == NULL)
{
Close();
iError = -1;
return iError;
}
iIndex =
zip_file_add(m_psZip,
pcZipOutputPath,
psZipSource, ZIP_FL_OVERWRITE);
if(iIndex < 0)
{
Close();
return iIndex;
}
// Create password
int iRetPassword =
zip_set_default_password(m_psZip, pcPassword);
// password set ?
if (iRetPassword == -1)
{
Close();
return iRetPassword;
}
// Close zip file.
Close();
return iError;
}
When I'm calling this function, I'm getting OK and the zip file is created, What I'm missing here?
LibZip version 1.1.3-1, OS: fedora 25
Thanks.