Create a zip file in .net with a password

I am working on a project that I need to create a zip with a password protected from the contents of the file in C #.

Before using System.IO.Compression.GZipStream to create gzip content. Does .net have any features for creating a password protected zip or rar file?

+5
source share
2 answers

Take a look at DotNetZip

It has pretty geat documentation, and it also allows you to load DLLs at runtime as an inline file.

+3
source

Unfortunately, this structure does not have such functionality. There is a way to create ZIP files, but without a password. If you want to create password protected ZIP files in C #, I would recommend SevenZipSharp . This is basically a managed shell for 7-Zip.

SevenZipBase.SetLibraryPath(Path.Combine( Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? Environment.CurrentDirectory, "7za.dll")); SevenZipCompressor compressor = new SevenZipCompressor(); compressor.Compressing += Compressor_Compressing; compressor.FileCompressionStarted += Compressor_FileCompressionStarted; compressor.CompressionFinished += Compressor_CompressionFinished; string password = @"whatever"; string destinationFile = @"C:\Temp\whatever.zip"; string[] sourceFiles = Directory.GetFiles(@"C:\Temp\YourFiles\"); if (String.IsNullOrWhiteSpace(password)) { compressor.CompressFiles(destinationFile, sourceFiles); } else { //optional compressor.EncryptHeaders = true; compressor.CompressFilesEncrypted(destinationFile, password, sourceFiles); } 
+1
source

All Articles