• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

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: 43026
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?
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic