java绕过加密密码,Java:密码包(加密和解密)。无效键错误

i am doing a class with static methods to encrypt and decrypt a message using javax.crypto. I have 2 static methods that use ecipher and dcipher in order to do what they are supossed to do i need to initialize some variables (which are static also). But when i try to use it i get InvalidKeyException with the parameters i give to ecipher.init(...). I can't find why. Here is the code:

private static byte[] raw = {-31, 17, 7, -34, 59, -61, -60, -16,

26, 87, -35, 114, 0, -53, 99, -116,

-82, -122, 68, 47, -3, -17, -21, -82,

-50, 126, 119, -106, -119, -5, 109, 98};

private static SecretKeySpec skeySpec;

private static Cipher ecipher;

private static Cipher dcipher;

static {

try {

skeySpec = new SecretKeySpec(raw, "AES");

// Instantiate the cipher

ecipher = Cipher.getInstance("AES");

dcipher = Cipher.getInstance("AES");

ecipher.init(Cipher.ENCRYPT_MODE, skeySpec);

dcipher.init(Cipher.DECRYPT_MODE, skeySpec);

} catch (NoSuchAlgorithmException e) {

throw new UnhandledException("No existe el algoritmo deseado", e);

} catch (NoSuchPaddingException e) {

throw new UnhandledException("No existe el padding deseado", e);

} catch (InvalidKeyException e) {

throw new UnhandledException("Clave invalida", e);

}

}

解决方案

AES-256 (and AES-192) requires the Unlimited Strength Jurisdiction Policy Files (one fo the last downloads at http://java.sun.com/javase/downloads/index.jsp) to be installed for the JRE. Not having this support will result in the InvalidKeyException when attempting to use 192 or 256 bit keys, as in your class.

The maximum allowed key size for AES without unlimited strength is documented in the JCA Reference Guide for Java 6, and by this happens to be 128-bits.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值