• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Encryption / Decryption Problem

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you certain that hex2byte precisely reverses the effect of asHex?
 
Please do not shoot the fish in this barrel. But you can shoot at this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic