• 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.BadPaddingException - not using strings

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I am completely new to Java but am posting this here as similar issues seem to have come up here before.
I have STRUGGLED to complete a crypto assignment that has to be handed in in Java though I am not a java programmer. My code now works and implements Otway-Rees most of the time but then suddenly starts failing with the below exception. Most other reports of this exception I have come across seem to boil down to representing encrypted data as a string or character and the suggestion is to change it to a byte{] but I am already doing that (I think!!) The exception seems to mainly occur when I am decrypting rather than encrypting but most times it just works. Money on though it will produce the error when handed up to teacher so any and all help greatly appreciated.

javax.crypto.BadPaddingException
at gnu.javax.crypto.jce.cipher.CipherAdapter.engineDoFinal(libgcj.so.11)
at javax.crypto.Cipher.doFinal(libgcj.so.11)
at javax.crypto.Cipher.doFinal(libgcj.so.11)
at MyUtility.decrypt(MyUtility.java:11)
at ClientBOraConnectionHandler.run(ClientB.java:302)
at java.lang.Thread.run(libgcj.so.11)

 
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is nothing wrong with the code shown, which mean the problem is with some code you haven't shown.
 
Sally Molloy
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply. I am posting the code that calls the code I previously posted. I apologise in advance for posting so much code but I have already illustrated that I am not capable of identifying the relevant code


 
greg stark
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That code is pretty hard to read, but from what I can see it use a protocol that doesn't make sense for ciphertext. Ciphertext bytes can be anything, include the value 0. Your code seem to treat 0 specially, by incrementing a variable numNulls and then terminating the loop after 2 are received. I don't see how that can work.
 
Sally Molloy
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah sorry - the code is pretty horrendous but as I said I am not a Java programmer and everytime I tried to tidy anything up it seemed to produce compile errors!!!

Anyway, the 00 or nulls thing is the encoding that has been specified. I have to send out certain composite data made up of different sections. Two 00s (i.e. 00 00) indicates the end of a section and is meant to allow the recipient to parse it. Now there is the obvious problem that if the data contains an actual or "real" 00 you need to escape that. How you do that is you add a 01 after it. So in summary, if you want to write 'end of segment' you write 00 00; if you genuinely want to send 00 as part of the data you ssend 00 01.

This is what all the looping through byte[]s is about . Hopeless???
 
greg stark
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, ok, but now I'm out of ideas
 
Sally Molloy
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for looking though!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic