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.
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:
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