是RC4还是ARCFOUR?使用 SecretKeySpec 时出现 InvalidKeyException?

发布于 2024-11-06 03:29:05 字数 2378 浏览 6 评论 0原文

我尝试在我的电脑上运行我的应用程序,但我不断收到这个东西。我是否可能缺少一些库?

fabsam.crypto.CryptoException: java.security.InvalidKeyException: No installed provider supports this key: javax.crypto.spec.SecretKeySpec
    at fabsam.crypto.RC4Decoder.decode(RC4Decoder.java:37) ~[bin/:na]
    ... (skipped my projects stack trace)
    at java.lang.Thread.run(Thread.java:662) [na:1.6.0_25]
Caused by: java.security.InvalidKeyException: No installed provider supports this key: javax.crypto.spec.SecretKeySpec
    at javax.crypto.Cipher.a(DashoA13*..) ~[na:1.6]
    at javax.crypto.Cipher.init(DashoA13*..) ~[na:1.6]
    at javax.crypto.Cipher.init(DashoA13*..) ~[na:1.6]
    at fabsam.crypto.RC4Decoder.decode(RC4Decoder.java:27) ~[bin/:na]
    ... 5 common frames omitted

Caused by: java.security.InvalidKeyException: No installed provider supports this key: javax.crypto.spec.SecretKeySpec
    at javax.crypto.Cipher.a(DashoA13*..) ~[na:1.6]
    at javax.crypto.Cipher.init(DashoA13*..) ~[na:1.6]
    at javax.crypto.Cipher.init(DashoA13*..) ~[na:1.6]
    at fabsam.crypto.RC4Decoder.decode(RC4Decoder.java:25) ~[fabsam-08.05.11.jar:na]
    ... 5 common frames omitted

代码:

cipher.init(Cipher.DECRYPT_MODE,
                    new SecretKeySpec(key.getBytes(DEFAULT_CHARSET), ALGORITHM));

是否是因为我在 ALGORITHM 变量中使用的是 RC4 而不是 ARCFOUR? 当我尝试 ARCFOUR 时,我得到这样的信息:

fabsam.crypto.CryptoException: java.security.InvalidKeyException: Illegal key size or default parameters
    at fabsam.crypto.RC4Decoder.decode(RC4Decoder.java:37) ~[bin/:na]
    ... (skipped my projects stack trace)
    at java.lang.Thread.run(Thread.java:662) [na:1.6.0_25]
Caused by: java.security.InvalidKeyException: Illegal key size or default parameters
    at javax.crypto.Cipher.a(DashoA13*..) ~[na:1.6]
    at javax.crypto.Cipher.a(DashoA13*..) ~[na:1.6]
    at javax.crypto.Cipher.a(DashoA13*..) ~[na:1.6]
    at javax.crypto.Cipher.init(DashoA13*..) ~[na:1.6]
    at javax.crypto.Cipher.init(DashoA13*..) ~[na:1.6]
    at fabsam.crypto.RC4Decoder.decode(RC4Decoder.java:27) ~[bin/:na]
    ... 5 common frames omitted

好的,问题不在于代码。在服务器上运行得很好,没有错误。然而,在我的电脑上,它向我抛出 InvalidKeyException 异常。所以这与 jvm 相关。有什么想法吗?

编辑: 我现在发现我遇到了两个例外。不是立即,而是第一次使用非法密钥大小,然后没有安装提供商。运行我的项目时,我将算法设置为“ARCFOUR”。

I tried running my application on my pc, but I keep getting this thing. Is it possible that I'm missing some libraries?

fabsam.crypto.CryptoException: java.security.InvalidKeyException: No installed provider supports this key: javax.crypto.spec.SecretKeySpec
    at fabsam.crypto.RC4Decoder.decode(RC4Decoder.java:37) ~[bin/:na]
    ... (skipped my projects stack trace)
    at java.lang.Thread.run(Thread.java:662) [na:1.6.0_25]
Caused by: java.security.InvalidKeyException: No installed provider supports this key: javax.crypto.spec.SecretKeySpec
    at javax.crypto.Cipher.a(DashoA13*..) ~[na:1.6]
    at javax.crypto.Cipher.init(DashoA13*..) ~[na:1.6]
    at javax.crypto.Cipher.init(DashoA13*..) ~[na:1.6]
    at fabsam.crypto.RC4Decoder.decode(RC4Decoder.java:27) ~[bin/:na]
    ... 5 common frames omitted

Caused by: java.security.InvalidKeyException: No installed provider supports this key: javax.crypto.spec.SecretKeySpec
    at javax.crypto.Cipher.a(DashoA13*..) ~[na:1.6]
    at javax.crypto.Cipher.init(DashoA13*..) ~[na:1.6]
    at javax.crypto.Cipher.init(DashoA13*..) ~[na:1.6]
    at fabsam.crypto.RC4Decoder.decode(RC4Decoder.java:25) ~[fabsam-08.05.11.jar:na]
    ... 5 common frames omitted

Code:

cipher.init(Cipher.DECRYPT_MODE,
                    new SecretKeySpec(key.getBytes(DEFAULT_CHARSET), ALGORITHM));

Could it be because I'm using RC4 not ARCFOUR in the ALGORITHM variable?
When I try ARCFOUR I get this:

fabsam.crypto.CryptoException: java.security.InvalidKeyException: Illegal key size or default parameters
    at fabsam.crypto.RC4Decoder.decode(RC4Decoder.java:37) ~[bin/:na]
    ... (skipped my projects stack trace)
    at java.lang.Thread.run(Thread.java:662) [na:1.6.0_25]
Caused by: java.security.InvalidKeyException: Illegal key size or default parameters
    at javax.crypto.Cipher.a(DashoA13*..) ~[na:1.6]
    at javax.crypto.Cipher.a(DashoA13*..) ~[na:1.6]
    at javax.crypto.Cipher.a(DashoA13*..) ~[na:1.6]
    at javax.crypto.Cipher.init(DashoA13*..) ~[na:1.6]
    at javax.crypto.Cipher.init(DashoA13*..) ~[na:1.6]
    at fabsam.crypto.RC4Decoder.decode(RC4Decoder.java:27) ~[bin/:na]
    ... 5 common frames omitted

Okay, the problem is not with the code. On server this runs just fine with no errors. However on my pc it throws me that InvalidKeyException exception. So it's something with jvm related.. Any ideas?

Edit:
I now see that I'm getting both exceptions. Not at once, but first time the illegal key size and then no installed provider. I've the ALGORITHM set to "ARCFOUR" when running my project.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

街道布景 2024-11-13 03:29:05

As alluded to by @DaveHowes it is likely you are using a third-party JCE provider in the case of the first stacktrace, and that your keysize is invalid in the case of the second stacktrace.

Sun includes several providers whose parameters are documented here. Note that according to the documentation for the SunJCE provider, the name of the algorithm is "ARCFOUR", not "RC4". My guess is that when you specified "RC4" you got the 'fabsam' provider implementation, whatever that is. When you specified 'ARCFOUR' you got the Sun implementation. Note also the keysize restrictions which specify that 'ARCFOUR' must have a keysize between 40 bits and 1024 bits inclusive (that's 5 bytes and 128 bytes inclusive). The String object key in your program may be either too small or too large, please check this.

为人所爱 2024-11-13 03:29:05

经过大量的挣扎和搜索以及一切,我得到了正确的答案。
在这里检查我的问题:Java 安全性:非法密钥大小或默认参数?< /a> 如果您遇到此问题!

After lot of struggling and searching and everything, I got the right answer.
Check my question here: Java Security: Illegal key size or default parameters? if you are experiencing this problem!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文