Why does JPasswordField.getPassword() create a String with the password in it?

前端 未结 7 2029
长发绾君心
长发绾君心 2020-11-28 10:52

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

7条回答
  •  情深已故
    2020-11-28 11:47

    **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 Strings, no cut/copy).

提交回复
热议问题