I want to compress some files (into the ZIP format) and encrypt them if possible using C#. Is there some way to do this?
Can encryption be done as a part of the compression itself?
有关压缩,请查看System.IO.Compression
命名空间,有关加密,请查看System.Security.Cryptography
。
对于Zip压缩,您是否看过http://www.icsharpcode.net/OpenSource/SharpZipLib/
I know the question is already old, but I must add my two cents.
First, some definitions:
Now, System.IO.Compression does not do Zip archiving. It does deflate and gzip compression, thus will compress a single blob of data into another single blob of data.
So, if you're looking for an archive format that can group many files and folders, you need Zip libraries like:
If you only need to compress and encrypt a single blob of data, then look under System.IO.Compression and System.Security.Cryptography .
The GZipStream class is a native way to handle compression.
As for encryption, there are many ways to do it, most of them in the System.Security namespace. They can be done chained (encrypt a compressed stream or compress an encrypted stream).
Chilkat提供用于压缩和加密的.NET库。
I'm not sure if the steps can be combined, but .NET has good support for basic crypto. Here's an article on it .
If they cannot be combined, do compression first and then encryption. Compressing an already encrypted file will lead to poor compression ratios, because a lot of redundancy is removed.
Here is a useful topic:
Help in creating Zip files from .Net and reading them from Java
System.IO.Packaging namespace gives you useful classes to compress data in zip format and support rights management.
There isn't anything you can use directly in C#, however you can use some libraries from J# to do it for you:
http://msdn.microsoft.com/en-us/magazine/cc164129.aspx
Should do just what you want?
With regards to the encryption, have a look at these links:
http://www.codeproject.com/KB/security/fileencryptdecrypt.aspx
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.