Java AES 解密带有错误标头的 zip 文件

发布于 2025-01-06 03:49:08 字数 302 浏览 1 评论 0原文

当我解密 zip 流时,我遇到了一个奇怪的问题。

解密给定的流后,除了 8 个字节的标头之外,我得到了完全相同的字节数组。

它应该是 50 4B 03 04(根据 Zip 规范),但我得到了不同的结果。

当我在 C# 中解密相同的流时,标头是正确的。我使用 RijndaelManaged、模式 CBC、填充 ZeroBytePadding 和块大小 = 128

在 Java 中,我使用 AES/CBC/NoPadding 块大小 = 128 进行解密。

我相信原因是填充,但我不明白为什么其余字节是正确的。

I faced a strange issue when I am decrypting a zip stream.

After I decrypted the given stream I have exactly the same array of bytes apart from 8 bytes of header.

It should be 50 4B 03 04 (according to Zip spec) but I get different.

When I decrypt the same stream in c# the header is correct. I use RijndaelManaged, mode CBC, padding ZeroBytePadding, and block size = 128

In Java I use AES/CBC/NoPadding block size=128 to decrypt.

I believe the cause is padding but then I don't understand why the rest of bytes are correct.

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

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

发布评论

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

评论(1

高冷爸爸 2025-01-13 03:49:08

在 CBC 模式下,填充模式应该只影响消息的最后一个字节,而不是第一个字节(即从 ZeroBytePadding 到 NoPadding,您可能会在末尾添加一些 0 字节)。

如果您的第一个块不同(但其余块匹配),最可能的原因是加密和解密中的初始化向量不同。检查一下。

In CBC mode, the padding mode should only affect the last bytes of your message, not the first ones (i.e. from ZeroBytePadding to NoPadding you might get some added 0 bytes at the end).

If your first block is different (but the rest matches), the most probable cause is a different initialization vector in encryption and decryption. Check this.

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