Possible Duplicate:
Why is char[] preferred over string for passwords?
I read somewhere that storing a sensitive key as a char[] rather than a String is better because the latter can be found in the memory. It also makes a little sense because of JPasswordField’s getText() method being Deprecated.
Is this true?
Once you are done using the password in a
char[]you can always overwrite it with 0’s or random values. However, you can’t do that withStringobjects because they are immutable objects in Java and the strings will remain alive until the garbage collector kicks in and clears it.Here is an interesting note at http://docs.oracle.com/javase/6/docs/technotes/guides/security/crypto/CryptoSpec.html