• Post Reply Bookmark Topic Watch Topic
  • New Topic

Encryption / Decryption Problem  RSS feed

 
Hari Dhanakoti
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I had been working on the encryption and decryption process..

I repeatedly facing the problem of
javax.crypto.BadPaddingException: Given final block not properly padded

This problem arises whenever i try to decrypt. In the java API documentation here its specified as

Note: under doFinal method its specified as

if any exception is thrown, this cipher object may need to be reset before it can be used

again. I am not sure how to over come this problem and dont know how to reset the cipher object again.

http://java.sun.com/j2se/1.4.2/docs/api/javax/crypto/Cipher.html#doFinal

Thanks
Hari
 
K Aditi
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dont know how to reset the cipher object again

Did you try using init method again?
By the way, it would be helpful if you provide your code snippet for diagnosis.
 
Hari Dhanakoti
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Encryption




Decryption



If both encryption and decryption operation performed in the main() block it works fine. If we tempt to invoke on different methods it creates such a problem.
 
K Aditi
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


I think you are using two different keys for encryption and decryption.
AES is a symmetric cryptography algorithm, which means that encryption and decryption processes use a single key which has to be shared beforehand between both the parties.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you certain that hex2byte precisely reverses the effect of asHex?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!