• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

decryption resulting in BadPaddingException

 
Shital Joshi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Rancher
Posts: 42968
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This doesn't address the problem, but note that the DES cipher is obsolete and no longer safe to use; use AES instead.
 
Shital Joshi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The SecurityFaq points to a relevant article.
 
James Sabre
Ranch Hand
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Shital Joshi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic