问题
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.
回答1:
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.
回答2:
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!
来源:https://stackoverflow.com/questions/5929705/is-it-rc4-or-arcfour-invalidkeyexception-when-using-secretkeyspec