Reputation: 129
My task is to create the password protected ZIP with the SevenZipSharp library.
I managed to make the files contents locked with the password, however the archive structure - file names, directories hierarchy can be viewed in any of the WinZip, 7-Zip or Compressed folder.
I use the cmp.EncryptHeaders = true;
however it seems to have no effect...
How can I encrypt the files and directories names? Thanks.
static void Main(string[] args)
{
const string LibraryPath = @"C:\Program Files\7-Zip\7z.dll";
SevenZipCompressor.SetLibraryPath(LibraryPath);
var cmp = new SevenZipCompressor();
cmp.CompressionMethod = CompressionMethod.Default;
cmp.CompressionLevel = CompressionLevel.Fast;
cmp.ArchiveFormat = OutArchiveFormat.Zip; // compatible with WinZip and Compressed folder
cmp.ZipEncryptionMethod = ZipEncryptionMethod.ZipCrypto; // compatible with old WinZip
cmp.EncryptHeaders = true;
cmp.FileCompressionStarted += (sender, e) =>
{
Console.WriteLine(((FileNameEventArgs)e).FileName);
};
const string archive = @"C:\temp\12.3G.zip";
File.Delete(archive);
cmp.CompressDirectory(@"C:\temp\Photos", archive, "password");
}
Upvotes: 0
Views: 1085
Reputation: 14100
Looking at the source code, it appears the only way for that flag to take effect is to use SevenZip
for the OutArchiveFormat
.
From the source code:
if (EncryptHeaders && _archiveFormat == OutArchiveFormat.SevenZip && !SwitchIsInCustomParameters("he"))
{
names.Add(Marshal.StringToBSTR("he"));
var tmp = new PropVariant {VarType = VarEnum.VT_BSTR, Value = Marshal.StringToBSTR("on")};
values.Add(tmp);
}
Upvotes: 2