Java AES-256 decrypt with IGE [closed]

五迷三道 提交于 2019-12-05 08:08:43

问题


I'm trying to decrypt AES-256 with IGE. But i don't know how use 256 bit key.

in code key - byte[] with length == 32; IV.length == 32; BlockSize == 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);
}

回答1:


You are almost there. You should swap Xprev with YPrev in the function and X with Y. Warning: only tested against a single test vector.

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;
}


来源:https://stackoverflow.com/questions/17797582/java-aes-256-decrypt-with-ige

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!