This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
This indicates that you have corrupted your ciphertext. Make sure that the ciphertext generated by the encryption method is exactly the same as the ciphertext being decrypted and is of length (with the base64 encoding removed) a multiple of 8 .
Note - I absolutely hate your key generation since although it uses DH to generate a key it does not seem to use DH to agree a shared secret key between the sender and receiver.
Note 1 - your exception handling is at best poor since you lose most of the information (the stack trace) and you try to continue even though the encryption or decryption has failed. You should either just pass the exception back to the caller OR you should convert the exception to an exception of your own (I use an unchecked exception derived from Error since I regard any exception here as a system error and fatal) and pass that back to the caller. You certainly should not continue regardless.
Retired horse trader.
Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
David O'Meara wrote:Heh, Retired horse trader.
(and I wrote the double underline stuff, sorry)
Yep - 45 years man and boy as a horse trader before deciding that enough was enough. I have written my fair share of unpopular code when the business people (who paid my salary) insisted but thankfully I no longer have to.