public final class SecureString
extends java.lang.Object
implements java.lang.CharSequence, java.io.Closeable
| Constructor and Description |
|---|
SecureString(char[] chars)
Constructs a new SecureString which controls the passed in char array.
|
SecureString(java.lang.String s)
Deprecated.
Only use for compatibility between deprecated string settings and new secure strings
|
| Modifier and Type | Method and Description |
|---|---|
char |
charAt(int index) |
SecureString |
clone()
Returns a new copy of this object that is backed by its own char array.
|
void |
close()
Closes the string by clearing the underlying char array.
|
boolean |
equals(java.lang.Object o)
Constant time equality to avoid potential timing attacks.
|
char[] |
getChars()
Returns the underlying char[].
|
int |
hashCode() |
int |
length() |
SecureString |
subSequence(int start,
int end) |
java.lang.String |
toString()
Convert to a
String. |
public SecureString(char[] chars)
@Deprecated public SecureString(java.lang.String s)
public boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic int length()
length in interface java.lang.CharSequencepublic char charAt(int index)
charAt in interface java.lang.CharSequencepublic SecureString subSequence(int start, int end)
subSequence in interface java.lang.CharSequencepublic java.lang.String toString()
String. This should only be used with APIs that do not take CharSequence.toString in interface java.lang.CharSequencetoString in class java.lang.Objectpublic void close()
close in interface java.io.Closeableclose in interface java.lang.AutoCloseablepublic SecureString clone()
try (SecureString copy = secureString.clone()) {
// pass thee char[] to a external API
PasswordAuthentication auth = new PasswordAuthentication(username, copy.getChars());
...
}
clone in class java.lang.Objectpublic char[] getChars()
clone() and pass its chars to the
consumer when the chars are needed multiple times.