Skip to content

IV不应该等于key #33

@kexinoh

Description

@kexinoh

在你的代码:

private static byte[] aes(byte[] encrypted, byte[] aesKey, int mode) {
Assert.isTrue(aesKey.length == 32, "IllegalAesKey, aesKey's length must be 32");
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
SecretKeySpec keySpec = new SecretKeySpec(aesKey, "AES");
IvParameterSpec iv = new IvParameterSpec(Arrays.copyOfRange(aesKey, 0, 16));
cipher.init(mode, keySpec, iv);
return cipher.doFinal(encrypted);
}

中使用了IV=KEY。
攻击方案:
截获密文:攻击者截获一段使用IV = Key加密的密文C = (C1, C2, C3, ..., Cn)。
构造特制密文:攻击者构造一个新的密文C' = (C1, 0, C1, C2, C3, ..., Cn),其中0表示一个全零的块。
解密过程:解密C1时,P1 = AES_decrypt(C1, Key) XOR Key。解密第二个块时,P2 = AES_decrypt(0, Key) XOR C1。解密第三个块时,P3 = AES_decrypt(C1, Key) XOR 0。恢复Key:由于P1 = AES_decrypt(C1, Key) XOR Key,且P3 = AES_decrypt(C1, Key),所以P1 XOR P3 = Key。
可以参阅:https://cedricvanrompay.gitlab.io/cryptopals/challenges/27.html
三、修复方案
IV应该设置为随机数,然后拼接在密文前面。
解密使再取下来即可。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions