我的任务是使用SevenZipSharp库创建受密码保护的邮政编码。
我设法使文件内容锁定与密码,但归档结构-文件名,目录层次结构可以在任何WinZip,7-Zip或压缩文件夹中查看。
我使用cmp.EncryptHeaders = true;,但是它似乎没有任何效果……
如何加密文件和目录名?谢谢。
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");
}发布于 2013-01-15 00:07:14
查看源代码,似乎该标志生效的唯一方法是对OutArchiveFormat使用SevenZip。
从源代码中:
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);
}https://stackoverflow.com/questions/14321964
复制相似问题