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.Object
public int hashCode()
hashCode
in class java.lang.Object
public int length()
length
in interface java.lang.CharSequence
public char charAt(int index)
charAt
in interface java.lang.CharSequence
public SecureString subSequence(int start, int end)
subSequence
in interface java.lang.CharSequence
public java.lang.String toString()
String
. This should only be used with APIs that do not take CharSequence
.toString
in interface java.lang.CharSequence
toString
in class java.lang.Object
public void close()
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
public 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.Object
public char[] getChars()
clone()
and pass its chars to the
consumer when the chars are needed multiple times.