Java AES-256用IGE解密 [英] Java AES-256 decrypt with IGE
本文介绍了Java AES-256用IGE解密的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在代码键 - byte [] em> length == 32; IV 。长度 == 32; BlockSize == 16
密码密码= 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]; (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);
}
解决方案
你几乎在那里您应该使用 Xprev
与 YPrev
在功能和 X
与 Y
。警告:只针对单个测试向量进行测试。
public static final byte [] ige(final byte [] key,final byte [] IV,
final byte [] Message)throws异常{
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 [] decryptpted = new byte [0];
byte [] y,x; (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(decryptiled,y);
}
返回解密;
}
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);
}
解决方案
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;
}
这篇关于Java AES-256用IGE解密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文