I am working on a school project and am having a bit of a problem with the two following functions. If I use the ImportArray function it will throw an IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padded cipher. As far as I could tell that was because the byte arrays I was creating on the import from the input strings after they were split up were not the same as before. Perhaps I am viewing this all wrong. Any chance you could tell me where I have made a mistake here?

I have no idea what you are trying to do, what your problem is or where it is occuring. Any chance you can provide more information?

August 16th, 2011, 11:15 PM

Norm

Re: IllegalBlockSizeException Problem

Your code is using a lot of third party classes. There is no way we can help you use them.
If we were to help, You need to provide us with the import statements you use to compile your program and the API doc for all the third party classes you are using.

Is your code getting the exception when it executes
or is your code supposed to throw the exception when it detects the error?

August 16th, 2011, 11:17 PM

GeekWarth

Re: IllegalBlockSizeException Problem

The program stores student account information which would include first name, last name, what the name of the current test is, if the student has completed it, and if they have a grade for the test, what it is. After being encrypted, this information is all exported to a file called students.txt via a string with delimiters. The ImportArray Function is for the Instructor Role to be able to load a class list and view the information. It will have to be seperated back up into the byte arrays and decrypted. That is where the problem is.

August 16th, 2011, 11:17 PM

Spidey1980

Re: IllegalBlockSizeException Problem

I would move that there is something seriously wrong with you code if it is throwing all those exceptions that you have to handle. You should figure out what is throwing the exceptions and fix each one - one at a time.

Please post complete code and copy and paste the errors from the console so that we may further help you.

Please copy and paste here the full text of your error messages.
To copy the contents of the command prompt window:
Click on Icon in upper left corner
Select Edit
Select 'Select All' - The selection will show
Click in upper left again
Select Edit and click 'Copy'

Paste here.

August 16th, 2011, 11:23 PM

GeekWarth

Re: IllegalBlockSizeException Problem

Everything from the Console"

Exception in thread "main" javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padded cipher
at com.sun.crypto.provider.CipherCore.doFinal(CipherC ore.java:750)
at com.sun.crypto.provider.CipherCore.doFinal(CipherC ore.java:676)
at com.sun.crypto.provider.DESCipher.engineDoFinal(DE SCipher.java:314)
at javax.crypto.Cipher.doFinal(Cipher.java:2086)
at EncryptionManager.DecodeDataString(EncryptionManag er.java:35)
at StudentManager.ImportArray(StudentManager.java:94)
at StudentManager.testSystem(StudentManager.java:178)
at StudentManager.initialize(StudentManager.java:57)
at TestManager.InitializeCore(TestManager.java:45)
at TestManager.main(TestManager.java:31)

August 16th, 2011, 11:32 PM

Junky

Re: IllegalBlockSizeException Problem

Isn't the exception obvious? Your input must have a length which is a multiple of 8. The input you are passing in is not a multiple of 8. So find out why and rectify that.

August 16th, 2011, 11:34 PM

Norm

Re: IllegalBlockSizeException Problem

Quote:

IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padded cipher

What is the length of the byte array that is passed to the doFinal method()?
Why isn't it a multiple of 8?

August 16th, 2011, 11:41 PM

GeekWarth

Re: IllegalBlockSizeException Problem

I understood that. However, I don't see what it would no longer have a length of 8. It had one before it was exported.

August 16th, 2011, 11:43 PM

Spidey1980

Re: IllegalBlockSizeException Problem

It's not a multiple of 8 because you only initalized the array of students. It is an empty array. It needs to be filled with data. Your export from the file is not going where it should.

August 16th, 2011, 11:45 PM

GeekWarth

Re: IllegalBlockSizeException Problem

Actually it is Spidey because I did it with the testSystem function I threw in there. There are three students added.

August 16th, 2011, 11:51 PM

GeekWarth

Re: IllegalBlockSizeException Problem

all I can tell you with the length is that if I do a System.err.print for byte[] temp1 in each of the functions, the ExportArray lenght comes up as 8816 and the ImportArray function has 111111. No earthly idea why.

August 16th, 2011, 11:53 PM

Junky

Re: IllegalBlockSizeException Problem

Quote:

Originally Posted by GeekWarth

I don't see what it would no longer have a length of 8.

That is the crux of the problem. You need to debug your code and find out why the length is not a multiple of 8. Place a bunch of print statements throughout your code to find out exactly what data is being used.

August 16th, 2011, 11:59 PM

GeekWarth

Re: IllegalBlockSizeException Problem

Junky, I spent most of my day doing that very thing. All I know is that if System.err.print for byte[] temp1 throughout byte[] temp5 in the ExportArray function, they will look exactly the same to the strings splitter[i] through splitter[i+4] in the ImportArray function. As soon as you try to convert those strings over to byte arrays, it all falls apart.

August 17th, 2011, 12:12 AM

Mr.777

Re: IllegalBlockSizeException Problem

Don't you think that splitter gets different bytes each time???
Try writing System.err.print under each line where you assigning splitter to byte and find the size of array. I guess if splitter is not getting multiple of 8.

August 17th, 2011, 04:17 AM

GeekWarth

Re: IllegalBlockSizeException Problem

OK since I am only making changes at this point to Import and Export Array functions so far, I am only including those. I changed things again, but to greatly simplify and remove the process of delimiting the byte arrays and strings before they were encoded. It is much cleaner this way, and should have actually worked, but I am still having the same problems.

here is the console output:
[B@31fa7bbf
[B@1ea40b04
Exception in thread "main" javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padded cipher
at com.sun.crypto.provider.CipherCore.doFinal(CipherC ore.java:750)
at com.sun.crypto.provider.CipherCore.doFinal(CipherC ore.java:676)
at com.sun.crypto.provider.DESCipher.engineDoFinal(DE SCipher.java:314)
at javax.crypto.Cipher.doFinal(Cipher.java:2086)
at EncryptionManager.DecodeDataString(EncryptionManag er.java:37)
at StudentManager.ImportArray(StudentManager.java:82)
at StudentManager.testSystem(StudentManager.java:166)
at StudentManager.initialize(StudentManager.java:61)
at TestManager.InitializeCore(TestManager.java:45)
at TestManager.main(TestManager.java:31)

Right now I am just trying to find away to directly create a byte array from the stream that works. Apparently this does not.

August 17th, 2011, 07:50 AM

Norm

Re: IllegalBlockSizeException Problem

Quote:

trying to find away to directly create a byte array from the stream that works.

Can you post a small program that does only that to work on to solve that problem without the rest of the code?

Use Arrays toString() to show the contents of the array
or print the array's length

August 17th, 2011, 11:44 AM

GeekWarth

Re: IllegalBlockSizeException Problem

Umm...actually I beleive the programming gods were seriously screwwing with me last night. Because I woke this morning, cleaned out a few little pieces of unused extra and this works now. Go figure.

August 18th, 2011, 05:28 AM

Mr.777

Re: IllegalBlockSizeException Problem

@GeekWarth: Try to print the value of offset, if it's -1, then in the loop set condition as offset!=-1
Try this and share here.
Also, try to write a test program that compose of 5 to 10 lines so that everyone could help you and you could use that in your main program.