Illegal Argument Exception while decrypting with Bouncy Castle Crypto
Can any one point me in the right direction. I am not sure why I am getting an illegal argument exception while decrypting a key. This used to wor开发者_JAVA技巧k earlier. Here is the stacktrace.
java.lang.IllegalArgumentException: DES key too long - should be 8 bytes
at org.bouncycastle.crypto.engines.DESEngine.init(Unknown Source)
at org.bouncycastle.crypto.modes.CBCBlockCipher.init(Unknown Source)
at org.bouncycastle.crypto.BufferedBlockCipher.init(Unknown Source)
at com.project.util.Encryptor.decrypt(Encryptor.java:90)
at com.project.util.Encryptor.decryptString(Encryptor.java:103)
at com.project.util.EncryptionUtil.getdecryptedlicense(EncryptionUtil.java:145)
at com.project.util.EncryptionUtil.<clinit>(EncryptionUtil.java:52)
at com.project.ebiz.security.jaas.SQLLoginModule.login(SQLLoginModule.java:176)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at javax.security.auth.login.LoginContext.invoke(LoginContext.java:769)
at javax.security.auth.login.LoginContext.access$000(LoginContext.java:186)
at javax.security.auth.login.LoginContext$4.run(LoginContext.java:683)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.login.LoginContext.invokePriv(LoginContext.java:680)
at javax.security.auth.login.LoginContext.login(LoginContext.java:579)
I would have to be a mind reader since you show no code at all. I'll make the following WAG:
You are using an 8 long character string to store a hard-coded key, and using the String.getBytes()
method to convert it to a byte array. This method uses the platform default character set, almost always a big no-no. On the platforms you've tested on, the default charset is something like US-ASCII that always converts one character to one byte. On the platform you are running into problems on, the default charset is a UTF-16 variant.
That's my guess.
精彩评论