• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm using "DES/ECB/PKCS5Padding" getting the following error when decrypting my encrypted value.

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

It fails on the line "byte[] ciphertext = cipher.doFinal( cleartext );". Any ideas what I'm missing ?




Thanks In Advance
Jason
 
Jason Wylde
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After some testing I determined that if I go beyond 56 characters that I am encrypting then decrypting , that is where it fails ( on the decrypt ) . Does this have something to do with DES being 56bit ?
 
Jason Wylde
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I may have figured it out. When writing the encrypted value to a file if it's too long it is putting a line break/carriage return into the string and then when it tries to decrypt the line ( which is now stored as 2 lines ) it doesn't match and thus won't work.

Can I prevent the carriage return / line feeds ?
 
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code you showed doesn't write or read anything, so there's no way of knowing! It sounds like it is an issue with your base64 encoder/decoder.
 
Jason Wylde
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the code that is doing the writing to the file. Hopefully someone can notice something I have missed which would cause line breaks within the encrypted text.





 
Rancher
Posts: 4686
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jason Wylde wrote:Can I prevent the carriage return / line feeds ?


Don't use a Base64 decoder. The standard specs for it say that it wraps lines. Or, make sure you filter out the whitespace properly both in and out.

Also, the algorithms are defined on arrays of unsigned octets. This is not at all the same as a Java String.
 
He repaced his skull with glass. So you can see his brain. Kinda like this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic