0
votes

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.

2
what jvm version are your running on? ie java -versionMeBigFatGuy
Don't know much about RC4, but this error message usually indicates that no security providers declared in the jvms' lib/security/java.security file are able to process the form of encryption you have asked for. If you are using an encryption provider that is not delivered as part of the jvm then it will probably have instructions on how to add it to this file.DaveH
@DaveHowes, I can't seem to figure out what encryption provider the previous developers were using to find it's instructions..Rihards
@DaveHowes, added more information..Rihards
The next step I'd take here is to compare the contents of the JVM's lib/security/java.security on the server to the corresponding file on your PC. I'd expect to see additional "provider" lines on the server. They look like "security.provider.1=sun.security.provider.Sun". If there are additional entries in the servers file, put the corresponding lines in the file on your PC. If probably won't fix all your problems, but it'll hopefully move you forwards.DaveH

2 Answers

0
votes

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.

0
votes

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!