Thanks for reading my post.
I�m using javax.swing.JPasswordField to read a user entered password. The extracted password (via the getPassword() method) is ued as a seed to create a SecureKey which will be used for encrypting some file contents.
I encrypt the original file contents by hard coding the password on a
test program. I use the same set of classes with the Swing GUI too. But when I obtain the password from the JPasswordField object, my cipher instance is throwing the exception: "javax.crypto.BadPaddingException: Given final block not properly padded".
When I hardcode the password in the GUI code I am able to successfully de-cipher the file. I did print the password obtained from the JPasswordField to console and it prints correctly.
I undertand that javax.crypto.spec.SecureKeySpec is considering byte values for the seed and if there is a difference in this the key would be different.
Is there any specific encoding or something I should use to convert the JPasswordField.getPassword() output to a
String?
Currently I'm using the String constructor:
String(char[] chars)
to convert the output of the JPasswordField.getPassword().