-
I am in need of finding out what type of encryption is used when adding files to a Zipfile object with a password set. Alternatively, I have the code shown below, is there any alternative way of adding files that I am missing which would allow me to specify an AES key length? using (ZipFile zip = ZipFile.Create($"{archiveOutputFolder}\\{pack.Name}.zip"))
{
zip.BeginUpdate();
zip.Password = _cryptKey;
foreach (var file in pack.Files)
{
zip.Add(new StaticDiskDataSource(file.Info.FullName), file.RelativeFilePath, CompressionMethod.Stored);
}
zip.CommitUpdate();
zip.Close();
return zip.Name;
} |
Beta Was this translation helpful? Give feedback.
Answered by
piksel
Feb 10, 2021
Replies: 1 comment 1 reply
-
using(var zipStream = new ZipOutputStream(File.Create($"{archiveOutputFolder}\\{pack.Name}.zip")))
{
zipStream.Password = _cryptKey;
foreach (var file in pack.Files)
{
var entry = new ZipEntry(file.RelativeFilePath);
entry.AESKeySize = 256;
zipStream.PutNextEntry(entry);
using(var sourceStream = File.OpenRead(file.Info.FullName))
{
sourceStream.CopyTo(zipStream);
}
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Hogedal
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ZipFile
doesn't support adding files with AES encryption. But you can useZipOutputStream
instead: