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.
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.