• 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 ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
  • Himai Minh
  • Carey Brown
  • salvin francis

BadPaddingException issue

Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to learn how to use the DES en/decryption in Java and am running into a problem with what seems to be a very basic test.

When i run this I get a BadPaddingException. I am using an 8-byte array, so I do not see why that should happen. If I check the block length with dcipher.getBlockLengt(), it does give eight, so I would think that an array of exactly 8 bytes would work.

Also, I know that this result would be garbage - the "encrypted" text and key are just for testing purposes. I'm just trying to see it work.

Thanks in advance for any feedback.

Ranch Hand
Posts: 820
IntelliJ IDE VI Editor Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that since you are just trying to decrypt something that was never encrypted, you are missing some elements of a DES created cipherText.

when I try this code:

output is:

I'm seeing that the DES stuff has special bytes ([B@) prepended to the ciphertext
so your DECRYPT operation doesn't see a byte array that looks like DES ciphertext and it is complaining.

I was looking for a way to turn off this requirement by specifying NOPADDING and get you the nonsense output you were looking for, but I couldn't figure it out. This, by the way is a great way to learn about these libraries, doing basic experiments and understanding why they fail. (I learned a lot anyway)
So I left, I came home, and I ate some pie. And then I read this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic