1

我正在尝试使用 IGE 解密 AES-256。但我不知道如何使用 256 位密钥。

在代码中-长度== 32的字节 [] ;长度== 32; 块大小== 16

Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding");
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(key, "AES"));

Xprev = java.util.Arrays.copyOfRange(IV, 0, BlockSize);
Yprev = java.util.Arrays.copyOfRange(IV, BlockSize, IV.length);

Decripted = new byte[0];

for (int i = 0; i < Message.length; i += BlockSize) { 
    Y = java.util.Arrays.copyOfRange(Message, i, i+BlockSize); 
    X = XOR(cipher.doFinal(XOR(Y,Xprev)), Yprev);
    Xprev = X;
    Yprev = Y;

    Decripted = sumBytes(Decripted, X);
}
4

1 回答 1

7

你快到了。您应该在函数中交换Xprevwith和with 。警告:仅针对单个测试向量进行测试。YPrevXY

public static final byte[] ige(final byte[] key, final byte[] IV,
        final byte[] Message) throws Exception {

    final Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding");
    cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(key, "AES"));

    final int blocksize = cipher.getBlockSize();

    byte[] xPrev = Arrays.copyOfRange(IV, 0, blocksize);
    byte[] yPrev = Arrays.copyOfRange(IV, blocksize, IV.length);

    byte[] decrypted = new byte[0];

    byte[] y, x;
    for (int i = 0; i < Message.length; i += blocksize) {
        x = java.util.Arrays.copyOfRange(Message, i, i + blocksize);
        y = xor(cipher.doFinal(xor(x, yPrev)), xPrev);
        xPrev = x;
        yPrev = y;

        decrypted = sumBytes(decrypted, y);
    }

    return decrypted;
}
于 2013-07-22T22:24:29.667 回答