Bookmark Topic Watch Topic
  • New Topic

AES SecretKeySpec object varies in two instances with same passphrase.  RSS feed

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi Experts,

I wrote a Linux application, a part of which will encrypt and decrypt a string using AES encryption. Given below is the SecretKeySpec creation method for the same. The application works perfectly and writes an encrypted string to a file. During decryption it correctly decrypts this string and use it in the application.



The issue:
Now i am writing a standalone java class to decrypt the encrypted string using the same pass phrase and code. So i wrote the decryption code standalone and provided it with same pass phrase and encrypted string as inputs. But it kept on failing with this error.

javax.crypto.BadPaddingException: Given final block not properly padded

I noticed that the issue was because the SecretKeySpec was different in the application and in my standalone class even though the pass phrase and code is same. I confirmed it using the hash value of SecretKeySpec object.

I am confused as to why this is happening as everything is same in the application jar and in the new standalone java file. Any help will be appreciated to understand this issue.

Thanks,

Arun
 
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please do not post the same question to multiple forums: CarefullyChooseOneForum

Let's continue the discussion in this duplicate thread.
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!