The GZipStream class is a native way to handle compression.
As for encryption, there are manyways 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).
I know the question is already old, but I must add my two cents.
First, some definitions:
Zip: Archive format for regrouping files and folders into a single file, and optionally encrypting data.
Deflate: One of the compression algorithms used within a Zip file to compress the data. The most popular one.
GZip: A single file compressed with deflate, with a small header and footer.
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 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.
发布评论
评论(9)
对于压缩,请查看
System.IO.Compression
命名空间和加密请参见System.Security.Cryptography
。For compression, look at the
System.IO.Compression
namespace and for encryption look atSystem.Security.Cryptography
.GZipStream 类是处理压缩的本机方法。
至于加密,有很多 方法 来实现这一点,其中大部分位于 System.Security 命名空间中。 它们可以链接起来(加密压缩流或压缩加密流)。
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).
我知道这个问题已经很老了,但我必须补充两点。
首先,一些定义:
现在,System.IO.Compression不执行 Zip 归档。 它进行 deflate 和 gzip 压缩,从而将单个数据块压缩为另一个单个数据块。
因此,如果您正在寻找一种可以对多个文件和文件夹进行分组的存档格式,则需要 Zip 库,例如:
如果您只需要压缩和加密单个 blob数据,然后查看 System.IO.Compression 并System.Security.Cryptography。
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.
对于 Zip 压缩,您是否见过 http://www.icsharpcode.net/OpenSource/SharpZipLib/
For Zip Compression, have you seen http://www.icsharpcode.net/OpenSource/SharpZipLib/
Chilkat 提供用于压缩和加密的 .NET 库。
Chilkat provides .NET libraries for compression and encryption.
没有任何东西可以直接在 C# 中使用,但是您可以使用 J# 中的一些库来为您完成此操作:
http://msdn.microsoft.com/en-us/magazine/cc164129.aspx
应该做你想做的事吗?
关于加密,请查看以下链接:
http://www.codeproject .com/KB/security/fileencryptdecrypt.aspx
http://www.obviex. com/samples/EncryptionWithSalt.aspx
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
http://www.obviex.com/samples/EncryptionWithSalt.aspx
这是一个有用的主题:
帮助从 .Net 创建 Zip 文件并从 Java 读取它们
System.IO.Packaging 命名空间为您提供了有用的类来压缩 zip 格式的数据,并且 支持权限管理。
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.
如果无法组合,则先压缩再加密。 压缩已经加密的文件将导致压缩率较低,因为大量冗余被删除。
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.
我不确定这些步骤是否可以组合,但 .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.