2

I'm using seven zip sharp and am having issues trying to add a file to an encrypted archive. Appending to a non-encrypted archive (with appropriate methods) seems to work, but an encrypted archive throws this following error

Invalid archive: open/read error! Is it encrypted and a wrong password was provided?
If your archive is an exotic one, it is possible that SevenZipSharp has no signature 
for its format and thus decided it is TAR by mistake. Message: Can not update the archive:
Open() failed.

I was wondering if anyone else has performed this successfully Here is some sample code im using

void AppendEncFilefile(Stream docstream, string addfilename, string archivename)
{          

    SevenZip.SevenZipCompressor compressor = new SevenZip.SevenZipCompressor();
    compressor.CompressionMode = SevenZip.CompressionMode.Append;
    compressor.CompressionLevel = SevenZip.CompressionLevel.Ultra;
    compressor.ArchiveFormat = SevenZip.OutArchiveFormat.SevenZip;
    compressor.EncryptHeaders = true;

    //this fails : trying to pass archive and file to add
    compressor.CompressFilesEncrypted(datafile, "password", addfilename);
    //this fails : trying to pass stream containg data to be written, and filename to save as
    compressor.CompressStreamDictionary(
          new Dictionary<string, System.IO.Stream>() 
              { 
                 { addfilename, xmldocstream } 
              }
          , archivename, "password");    
}

Thanks

Dawood Moazzem
  • 163
  • 3
  • 11

2 Answers2

0

I have the same problem. I "solved" this by compressing without encryption, but adding a +1 file with encryption. The 7z file manager asked for password, and 7z contained all files - it was enough for me. Of course the file manager listed the rest of the files being non-encrypted.

Still looking for a GOOD way to solve this, but for a workaround it just does the trick for a while.

Zéiksz
  • 688
  • 1
  • 11
  • 25
0

Had the same problem try :

 compressor.ArchiveFormat = SevenZip.OutArchiveFormat.Zip;

istead of :

 compressor.ArchiveFormat = SevenZip.OutArchiveFormat.SevenZip;
Teodor Głaz
  • 61
  • 1
  • 5