I inherited an old java project from 2006 (the original developer was long gone, and I had never coded Java before), where I get this error:
EncryptionException: javax.crypto.IllegalBlockSizeException: input length must be a multiple of 8 when decrypting with advanced encryption
The code that he refers to is as follows:
public String decrypt( String encryptedString ) throws EncryptionException { if ( encryptedString == null || encryptedString.trim().length() <= 0 ) throw new IllegalArgumentException( "encrypted string was null or empty" ); try { SecretKey key = keyFactory.generateSecret( keySpec ); cipher.init( Cipher.DECRYPT_MODE, key ); BASE64Decoder base64decoder = new BASE64Decoder(); byte[] cleartext = base64decoder.decodeBuffer( encryptedString ); byte[] ciphertext = cipher.doFinal( cleartext ); return bytes2String( ciphertext ); } catch (Exception e) { throw new EncryptionException( e ); } }
I am not entirely sure about the internal workings of the program, but I know that there are several configuration files and a key.properties file in this project directory. Regarding the "Input Length" (as indicated in the error message), my password for the database is 15 characters, and the "key" in key.properties is 25 characters. I have no idea if it matters or not.
Notes:
- I tried to change the database password to 16 characters (a multiple of 8), but to no avail.
- I read this and this and they didn’t help
- I am moving this project from one server to another. It runs on its source server.
- The source server runs JRE 1.4.2. The new server launches JRE 1.6u27.
- I REALLY do not want to rebuild .jar. I am not a Java developer, and the project is quite massive.
Thank you for your help.
source share