我正在使用 7 个 zip sharp 并且在尝试将文件添加到加密存档时遇到问题。附加到非加密存档(使用适当的方法)似乎有效,但加密存档会引发以下错误
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.
我想知道是否有人成功执行了此操作这是我正在使用的一些示例代码
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");
}
谢谢