• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4803
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Brace yourself while corporate america tries to sell us its things. Some day they will chill and use tiny ads.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic