public class WmSecureString
extends java.lang.Object
implements java.io.Serializable
This class addresses security concerns related to String storage in memory, specifically the immutable string issue that prevents explicit erasure of string characters. This class is a mutable alternative to String, allowing characters to be removed from memory. The stored characters are kept in memory as clear text until erased.
Constructor and Description |
---|
WmSecureString(byte[] inArray)
Constructs WmSecureString from a byte array, using the default encoding.
|
WmSecureString(byte[] inArray,
java.lang.String inEncoding)
Constructs WmSecureString from a byte array, using a specified encoding.
|
WmSecureString(char[] inArray)
Constructs WmSecureString from a character array.
|
WmSecureString(java.lang.String inStr)
Constructs WmSecureString from a string.
|
WmSecureString(WmSecureString inBuff)
Constructs WmSecureString from another secure string buffer.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object inObj)
Overrides java.lang.Object.equals() to compare chars.
|
void |
erase()
Erases the buffer contents.
|
char[] |
getChars()
Creates a byte array from the buffer contents, using the input encoding.
|
int |
hashCode()
Overrides java.lang.Object.hashCode().
|
void |
initFromByteArray(byte[] inArray,
java.lang.String inEncoding)
Initializes the buffer with a byte array.
|
int |
length()
Returns the number of characters in the buffer.
|
byte[] |
toByteArray()
Creates a byte array from the buffer contents, using the default encoding.
|
byte[] |
toByteArray(java.lang.String inEnc)
Creates a byte array from the buffer contents, using a specified encoding.
|
java.lang.String |
toString()
Creates a string from the buffer contents.
|
boolean |
wasErased()
Returns true if the secure string buffer is currently empty.
|
public WmSecureString(char[] inArray)
inArray
- Character array from which to populate the buffer.public WmSecureString(byte[] inArray)
inArray
- Byte array from which to populate the buffer.public WmSecureString(byte[] inArray, java.lang.String inEncoding) throws java.io.UnsupportedEncodingException
inArray
- Byte array from which to populate the buffer.inEncoding
- Identifier for the encoding to be used for conversion.java.io.UnsupportedEncodingException
- Thrown if the specified encoding is
not supported.public WmSecureString(java.lang.String inStr)
inStr
- String from which to populate the buffer.public WmSecureString(WmSecureString inBuff)
inBuff
- WmSecureString from which to populate the buffer.public int length()
public byte[] toByteArray()
public byte[] toByteArray(java.lang.String inEnc) throws java.io.UnsupportedEncodingException
inEnc
- Identifier for the encoding to be used for the conversion.java.io.UnsupportedEncodingException
- Thrown if the specified encoding is
not supported.public char[] getChars()
public java.lang.String toString()
toString
in class java.lang.Object
public void erase()
public boolean equals(java.lang.Object inObj)
equals
in class java.lang.Object
inObj
- Target object for comparison.public int hashCode()
hashCode
in class java.lang.Object
public boolean wasErased()
public void initFromByteArray(byte[] inArray, java.lang.String inEncoding) throws java.io.UnsupportedEncodingException
inArray
- Byte array to replace the current buffer contents.inEncoding
- Identifier for the encoding to be used for the conversion.java.io.UnsupportedEncodingException
- Thrown if the specified encoding is
not supported.