PKZIP加解密的密钥导出的正确处理过程是什么?

问题描述 投票:0回答:1

PKZIP流密码是一种对称加密方案,其中加密和解密都需要密钥。该密钥用于为一次性密码本算法生成密钥字节流。流密码的 96 位内部状态分为三个 32 位值,分别表示为 key0key1key2

这是根据这个

但是根据PKWARE APPNOTE

6.1.3 Each encrypted file has an extra 12 bytes stored at the start 
of the data area defining the encryption header for that file.  The
encryption header is originally set to random values, and then
itself encrypted, using three, 32-bit keys.  The key values are
initialized using the supplied encryption password.  After each byte
is encrypted, the keys are then updated using pseudo-random number
generation techniques in combination with the same CRC-32 algorithm
used in PKZIP and described elsewhere in this document.

6.1.4 The following are the basic steps required to decrypt a file:

1) Initialize the three 32-bit keys with the password.
2) Read and decrypt the 12-byte encryption header, further
   initializing the encryption keys.
3) Read and decrypt the compressed data stream using the
   encryption keys.

初始化加密密钥:

Key(0) <- 305419896
Key(1) <- 591751049
Key(2) <- 878082192

loop for i <- 0 to length(password)-1
    update_keys(password(i))
end loop

Where update_keys() is defined as:

update_keys(char):
  Key(0) <- crc32(key(0),char)
  Key(1) <- Key(1) + (Key(0) & 000000ffH)
  Key(1) <- Key(1) * 134775813 + 1
  Key(2) <- crc32(key(2),key(1) >> 24)
end update_keys

令人困惑的部分是我们在哪里以及如何获得 Keys(key0,key1,key2)?

下面是我用于测试上述步骤 1 和 2 的示例数据。

密码:

1234

12字节加密头:

3A CE 1D 8D E4 D1 ED D1 E5 08 4F EC

CRC:

E07B8FC3

现在获取三个32位密钥的正确方法是什么?

我需要理解这一部分才能编写我的 zip 恢复软件。

encryption zip pkzip
1个回答
0
投票

首先,您应该知道这种古老的 PKWare 加密方案非常弱,不应该用于您真正关心的保持加密以防止攻击的内容。您应该改用 AES 256,PKWare APPNOTE 中也描述了其用法。

其次,您在问题中展示了完整的算法。三个 32 位密钥是使用密码和这些步骤生成的。如果您要问的话,前三行是三个键的初始值。您继续使用

update_keys()
decrypt_byte()
来解密 12 字节标头,然后解密压缩数据。加密时,除了最后一个字节应为文件 CRC 的高字节外,其余 12 字节头是随机生成的。尽管误报率为 1/256,但这可以快速检查是否提供了正确的密码。

© www.soinside.com 2019 - 2024. All rights reserved.