This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes decryption resulting in BadPaddingException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "decryption resulting in BadPaddingException" Watch "decryption resulting in BadPaddingException" New topic
Author

decryption resulting in BadPaddingException

Shital Joshi
Greenhorn

Joined: Jun 30, 2010
Posts: 9


these are the encryption and decryption routines i am using in my chat application in p2p project
my code for encryption and decryption works properly for only lastly added member of my group.
for all existing group members it shows exception in decryption method as :

JAVAX.CRYPTO.BADPADDINGEXCEPTION:given final block not properly padded exception in decryption method

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41574
    
  54
This doesn't address the problem, but note that the DES cipher is obsolete and no longer safe to use; use AES instead.


Ping & DNS - my free Android networking tools app
Shital Joshi
Greenhorn

Joined: Jun 30, 2010
Posts: 9
Ulf Dittmer wrote:This doesn't address the problem, but note that the DES cipher is obsolete and no longer safe to use; use AES instead.


thanks for quick reply... can you please suggest me how to use AES in my functions
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41574
    
  54
The SecurityFaq points to a relevant article.
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

The BadPaddingException is probably just a symptom of your key agreement failing and is standard if you try to decrypt with a key you didn't encrypt with. The result of
should allow the generation of Alice's public DH key for your code to work and I'm not convinced it does.

You don't need to go thought all those contortions. Get the chat clients to send you their DH public key certificates and you send them your DH public key certificate.

P.S. It is normal to use Bob and Alice and not Bob and Bob1!


Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
Shital Joshi
Greenhorn

Joined: Jun 30, 2010
Posts: 9
James Sabre wrote:The BadPaddingException is probably just a symptom of your key agreement failing and is standard if you try to decrypt with a key you didn't encrypt with. The result of
should allow the generation of Alice's public DH key for your code to work and I'm not convinced it does.

You don't need to go thought all those contortions. Get the chat clients to send you their DH public key certificates and you send them your DH public key certificate.

P.S. It is normal to use Bob and Alice and not Bob and Bob1!


thank you very much for suggestion but the group key i am generating doesn't have problem, its getting generated same on all machines, still while decrypting message i am facing same problem with all machines except lastly joined one... why its happening ?
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

Shital Joshi wrote:

thank you very much for suggestion but the group key i am generating doesn't have problem, its getting generated same on all machines, still while decrypting message i am facing same problem with all machines except lastly joined one... why its happening ?


The problem is clearly a key agreement problem since, as I said in my first response, the BadPaddingException will likely occur 99.6% of the time of you try to decrypt with the wrong key. Your code for generating the Alice public key from the long integer looks suspect to me and I would concentrate on that.

Since I only have a very limited view of your code it is difficult say exactly what is wrong but you seem to be trying to use DH in a non standard manner using code that is highly suspect.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: decryption resulting in BadPaddingException