SevenZip,许多尾随 0

发布于 2024-08-05 09:55:17 字数 552 浏览 5 评论 0原文

我的数组是 140 字节。 outArray 是 512 字节...不是我想要的。我也不知道我是否正确加密。下面的代码正确吗?我该如何解决这个问题,以便 outArray 是实际大小,而不是用许多尾随零来固定?

        var compress = new SevenZipCompressor();
        compress.CompressionLevel = CompressionLevel.Ultra;
        compress.CompressionMethod = CompressionMethod.Lzma;
        compress.ZipEncryptionMethod = ZipEncryptionMethod.Aes256;
        var sIn = new MemoryStream(inArray);
        var sOut = new MemoryStream();
        compress.CompressStream(sIn, sOut, "a");
        byte[] outArray = sOut.GetBuffer();

My array is 140bytes. outArray is 512bytes... Not what i wanted. Also i dont know if i am encrypting properly. Is the code below correct? how do i fix this so outArray is the real size and not fixed with many trailing zeros?

        var compress = new SevenZipCompressor();
        compress.CompressionLevel = CompressionLevel.Ultra;
        compress.CompressionMethod = CompressionMethod.Lzma;
        compress.ZipEncryptionMethod = ZipEncryptionMethod.Aes256;
        var sIn = new MemoryStream(inArray);
        var sOut = new MemoryStream();
        compress.CompressStream(sIn, sOut, "a");
        byte[] outArray = sOut.GetBuffer();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青芜 2024-08-12 09:55:17

您正在获取整个 MemoryStream 缓冲区,您需要使用 ToArray(),

  byte[] outArray = sOut.ToArray();

这将删除尾随的零,但您仍然可能会获得比输入更大的数组。压缩/加密会产生开销,可能大于 140 字节。

You are getting the whole MemoryStream buffer, you need to use ToArray(),

  byte[] outArray = sOut.ToArray();

This will remove the trailing zeros but you may still get an array bigger than input. There is overhead with compression/encryption, which is probably bigger than 140 bytes.

原谅过去的我 2024-08-12 09:55:17

许多压缩算法(我不熟悉 7-zip 的具体细节)都会生成具有最小输出大小的输出。 7-zip 在大型输入数据集上表现最佳,140 字节并不算“大”。使用 gzip 或 lzo 之类的东西可能会做得更好。您还尝试过哪些其他压缩算法?

Many compression algorithms (I'm unfamiliar with the specific details for 7-zip) generate output with a minimum output size. 7-zip performs best on large input data sets, and 140 bytes is not "large". You might do better with something like gzip or lzo. What other compression algorithms have you tried?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文