Swing\'s JPasswordField has the getPassword() method that returns a char array. My understanding of this is that the array can be zeroed immediately after use so that you do
**I came across this while I was looking for a way to actually display some sensitive data on a Swing component without using a String object. Apparently there is no way to do it unless I am willing to rewrite part (all?) of the Swing API.. not gonna happen.
You can tell a JPasswordField
to display the characters by calling field.setEchoChar('\0')
. This retains the rest of the protection offered by JPasswordField
(no String
s, no cut/copy).