java.security.InvalidKeyException:在Android的非法密钥大小或默认参数 [英] java.security.InvalidKeyException: Illegal key size or default parameters in android

查看:208
本文介绍了java.security.InvalidKeyException:在Android的非法密钥大小或默认参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了下面的错误和我有点卡住:

i got the following error and i got a little stuck :

Exception in thread "main" java.security.InvalidKeyException: Illegal key size or default parameters
    at javax.crypto.Cipher.checkCryptoPerm(Cipher.java:1011)
    at javax.crypto.Cipher.implInit(Cipher.java:786)
    at javax.crypto.Cipher.chooseProvider(Cipher.java:849)
    at javax.crypto.Cipher.init(Cipher.java:1213)
    at javax.crypto.Cipher.init(Cipher.java:1153)
    at net.nakou.indie.wtext.engineClass.Session.cryptString(Session.java:52)

我坚持,因为所有我发现谈谈Java加密扩展(JCE),它通常被包含在Android SDK中的答案。所以我觉得我的问题不是这个。

I'm stuck because all the answers I've found talk about the Java Cryptography Extension (JCE) which be normally included into the android SDK. So I think my problem is not this one.

我一定是忘了什么事,但我不能找到什么。也许我的code是错误的(它的密码在Java中我的第一种方法,我不是专家,以下code主要是一些复制 - 粘贴的教程)。

I must have forgot something, but i can't find what. Maybe my code is wrong (it's my first approach of cryptography in Java, i'm not an expert, and the following code is mostly some copy-pastes of tutorials).

我用这个code隐窝和解密字符串:

I use this code to crypt and decrypt a String :

public String cryptString(String s) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, UnsupportedEncodingException, BadPaddingException, IllegalBlockSizeException {
    byte[] KeyData = this.cryptKey.getBytes();
    SecretKeySpec KS = new SecretKeySpec(KeyData, "Blowfish");
    Cipher cipher = Cipher.getInstance("Blowfish");
    cipher.init(Cipher.ENCRYPT_MODE, KS);
    String ret = new String(cipher.doFinal(s.getBytes("UTF-8")));
    return ret;
}

public String decryptString(byte[] s) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
    byte[] KeyData = this.cryptKey.getBytes();
    SecretKeySpec KS = new SecretKeySpec(KeyData, "Blowfish");
    Cipher cipher = Cipher.getInstance("Blowfish");
    cipher.init(Cipher.DECRYPT_MODE, KS);
    String ret = new String(cipher.doFinal(s));
    return ret;
}

和以下项:

private String cryptKey = "qkjll5@2md3gs5Q@FDFqf";

感谢你们。

推荐答案

私人字符串cryptKey =qkjll5 @ 2md3gs5Q @ FDFqf;

在默认情况下的Java仅支持128位的加密

By default Java supports only 128-bit encryption

128位== 16字节== 16个字符。

128bits == 16Bytes == 16 Chars.

所以 cryptKey 不能超过16个字符。

So cryptKey cannot exceed 16 characters.

如果你想超过16个以上的字符,你必须安装Java加密扩展(JCE)无限强度

If you want to exceed more than 16 character you have to install Java Cryptography Extension (JCE) Unlimited Strength.

为什么128位?

这篇关于java.security.InvalidKeyException:在Android的非法密钥大小或默认参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆