what would be the solution,when i comment initilizeKey() method in decryptValue method it is working.
but in my case i will be calling encryptValue one time and later decryptValue method.not both at a time.
any suggestion please.
Your initializeKey() method creates a random key each time it is called. Your encryptValue() method calls initializeKey() and creates a random key to encrypt with. Your decryptValue() method calls initializeKey() and creates another random, most probably different key from that used in the encryption key, to decrypt with. AES must use the same key for encryption and decryption.
The key should be generated once and saved. You can use a password protected Java Keystore for this.
P.S. You do realise that ECB block mode is considered insecure since it allows forgery though splicing. You should change to use one of the feedback modes such as CBC; this will eliminate this particular insecurity.
Retired horse trader.
Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
sudheer kiran wrote:hi thanks for the reply,when i use key store i am getting "should be 16 bit padding error".
Then you are using it wrongly! Not being a mind reader I can't help without seeing the code.
As I said in one of your other threads in this forum, you need to do some reading. By doing as you are doing and cobbling together code from random sources found on the Internet you might end up with something that encrypts and decrypts but based on what you have posted so far it will be insecure.
P.S. Paraphrasing error messages like that helps nobody.