public class SecureStringBuffer
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable
Application programmers do not usually have to consider how to destroy a
SecureStringBuffer passed within the Toolkit most
methods automatically wipe, or destroy, the SecureStringBuffer
object once it is no longer needed. However, this class includes a
wipe method to destroy SecureStringBuffer objects
that are not dealt with automatically.
The data in an instance of this class can be protected by an exclusive OR operation, xor, or by encryption. In the case of xor, the data is combined, using the exclusive OR operation, with a randomly generated value before it is committed to memory. In the case of encryption, the data is encrypted using a symmetric cipher before it is committed to memory. Data can be protected depending on its sensitivity:
BASE no protectionMEDIUM perform the xor operation on the
dataHIGH encrypt/decrypt the data
The default sensitivity is BASE.
MEDIUM or
HIGH requires that the Entrust cryptographic service
provider (CSP) be installed. The Entrust CSP is automatically
installed when a User logs into the Toolkit. Using these
sensitivities without logging into the Toolkit requires that the
Entrust CSP be installed manually prior to instantiation of this
class, otherwise a SecurityException will result. The
Initializer class can
be used to manually install the Entrust CSP.BASE or MEDIUM.| Modifier and Type | Field and Description |
|---|---|
static int |
BASE
Base sensitivity - do not obfuscate the data
|
static int |
HIGH
High sensitivity - encrypt the data
|
static int |
MEDIUM
Medium sensitivity - xor the data
|
| Constructor and Description |
|---|
SecureStringBuffer(char[] ca)
Creates a new
SecureStringBuffer from the given character
array. |
SecureStringBuffer(char[] ca,
int sensitivity)
Creates a new
SecureStringBuffer from the given character
array and using the specified sensitivity. |
SecureStringBuffer(java.io.InputStream is)
Deprecated.
use
SecureByteArray instead; since JTK 6.1 |
SecureStringBuffer(SecureStringBuffer ssb)
Copy constructor used to create a new instance of
SecureStringBuffer that is identical to the specified
SecureStringBuffer. |
SecureStringBuffer(java.lang.String s)
Deprecated.
Pass sensitive data in as a
StringBuffer or as a
char []. Using a String creates a copy of
the data in memory that cannot be destroyed. Since JTK 6.1. |
SecureStringBuffer(java.lang.StringBuffer sb)
Creates a
SecureStringBuffer from the given
StringBuffer. |
SecureStringBuffer(java.lang.StringBuffer sb,
int sensitivity)
Creates a
SecureStringBuffer from the given
StringBuffer and specified sensitivity. |
SecureStringBuffer(java.lang.StringBuilder sb)
Creates a
SecureStringBuffer from the given
StringBuilder. |
SecureStringBuffer(java.lang.StringBuilder sb,
int sensitivity)
Creates a
SecureStringBuffer from the given
StringBuilder and specified sensitivity. |
| Modifier and Type | Method and Description |
|---|---|
java.lang.Object |
clone()
Returns a clone of the
SecureStringBuffer. |
boolean |
equals(java.lang.Object obj)
Indicates whether some other object is "equal to" this one.
|
int |
getSensitivity()
Returns the sensitivity for this
SecureStringBuffer object. |
java.lang.StringBuffer |
getStringBuffer()
Returns a copy of the sensitive data as a
StringBuffer. |
byte[] |
toASCIIByteArray()
Deprecated.
use
toUSASCIIByteArray() instead; since 7.0patch |
byte[] |
toByteArray()
Returns a copy of the sensitive data as a
byte array, using
the default character encoding. |
byte[] |
toByteArray(java.lang.String enc)
Returns a copy of the sensitive data as a
byte array,
using the specified character encoding. |
char[] |
toCharArray()
Returns a copy of the sensitive data as a character array.
|
byte[] |
toISO88591ByteArray()
Returns a copy of the sensitive data as a
byte array,
using the ISO-8859-1 character encoding. |
SecureByteArray |
toSecureByteArray()
Securley transforms the
SecureStringBuffer to a
SecreByteArray using the default character encoding. |
SecureByteArray |
toSecureByteArray(java.lang.String enc)
Securley transforms the
SecureStringBuffer to a
SecreByteArray using the specified character encoding. |
java.lang.String |
toString()
Returns a copy of the sensitive data as a
String. |
java.lang.StringBuffer |
toStringBuffer()
Returns a copy of the sensitive data as a
StringBuffer. |
byte[] |
toUSASCIIByteArray()
Returns a copy of the sensitive data as a
byte array,
using the US-ASCII character encoding. |
byte[] |
toUTF8ByteArray()
Returns a copy of the sensitive data as a
byte array,
using the UTF-8 character encoding. |
void |
wipe()
Clears the sensitive data held as a
SecureStringBuffer. |
public static final int BASE
public static final int MEDIUM
public static final int HIGH
public SecureStringBuffer(char[] ca)
SecureStringBuffer from the given character
array.
After the SecureStringBuffer has been initialized, the
character array passed in as an argument is wiped from memory. Because
this constructor accepts a character array and not a* String,
it is possible to clear the memory. The sensitivity is set to the default
value BASE.
ca - the character array that contains the sensitive datajava.lang.IllegalArgumentException - thrown if the character array is nullpublic SecureStringBuffer(char[] ca,
int sensitivity)
SecureStringBuffer from the given character
array and using the specified sensitivity.
After the SecureStringBuffer has been initialized, the
character array passed in as an argument is wiped from memory. Because
this constructor accepts a character array and not a String,
it is possible to clear the memory.
ca - the character array that contains the sensitive datasensitivity - sensitivity of the datajava.lang.IllegalArgumentException - thrown if the character array is nullpublic SecureStringBuffer(java.io.InputStream is)
throws java.io.IOException
SecureByteArray instead; since JTK 6.1SecureStringBuffer by reading the sensitive
data from an InputStream.
The sensitivity is set to the default value BASE.
InputStream to this constructor
will be converted to characters using the String
constructor. This creates a copy of the data in memory that
cannot be destryed.InputStream might use buffers internally that
might not be cleared following use. If this is the case, you have
no means of destroying this data.is - the input stream from which the sensitive data will be readjava.io.IOException - thrown if a problem occurs while reading the InputStreamjava.lang.IllegalArgumentException - thrown if the input stream is nullpublic SecureStringBuffer(SecureStringBuffer ssb)
SecureStringBuffer that is identical to the specified
SecureStringBuffer.
SecureStringBuffer argument. If necessary, you can do
this by calling the wipe() method on the
argument.ssb - the secure string buffer to be copiedjava.lang.IllegalArgumentException - thrown if the secure string buffer is nullpublic SecureStringBuffer(java.lang.StringBuffer sb)
SecureStringBuffer from the given
StringBuffer.
After the SecureStringBuffer has been initialized, the
StringBuffer passed in as an argument is wiped from memory.
The sensitivity is set to the default value BASE.
sb - the string buffer that contains the sensitive datajava.lang.IllegalArgumentException - thrown if the string buffer is nullpublic SecureStringBuffer(java.lang.StringBuilder sb)
SecureStringBuffer from the given
StringBuilder.
After the SecureStringBuffer has been initialized, the
StringBuilder passed in as an argument is wiped from memory.
The sensitivity is set to the default value BASE.
sb - the string builder that contains the sensitive datajava.lang.IllegalArgumentException - thrown if the string builder is nullpublic SecureStringBuffer(java.lang.StringBuffer sb,
int sensitivity)
SecureStringBuffer from the given
StringBuffer and specified sensitivity.
After the SecureStringBuffer has been initialized, the
StringBuffer passed in as an argument is wiped from memory.
sb - the string buffer that contains the sensitive datasensitivity - sensitivity of the datajava.lang.IllegalArgumentException - thrown if the string buffer is nullpublic SecureStringBuffer(java.lang.StringBuilder sb,
int sensitivity)
SecureStringBuffer from the given
StringBuilder and specified sensitivity.
After the SecureStringBuffer has been initialized, the
StringBuilder passed in as an argument is wiped from memory.
sb - the string builder that contains the sensitive datasensitivity - sensitivity of the datajava.lang.IllegalArgumentException - thrown if the string buffer is nullpublic SecureStringBuffer(java.lang.String s)
StringBuffer or as a
char []. Using a String creates a copy of
the data in memory that cannot be destroyed. Since JTK 6.1.SecureStringBuffer instance taking a
String as an argument.
String to this constructor cannot be
destroyed using the wipe() method. The original
String continues to represent sensitive data after
calling this constructor.s - the string that contains the sensitive datapublic java.lang.Object clone()
SecureStringBuffer.clone in class java.lang.Objectpublic int getSensitivity()
SecureStringBuffer object.public java.lang.StringBuffer getStringBuffer()
StringBuffer.
StringBuffer is
cleared after use.public java.lang.StringBuffer toStringBuffer()
StringBuffer.
StringBuffer is
cleared after use.public byte[] toByteArray()
byte array, using
the default character encoding.
byte array is
cleared after use.public byte[] toASCIIByteArray()
toUSASCIIByteArray() instead; since 7.0patchbyte array,
using the an ASCII compatible character encoding.
byte array is
cleared after use.public byte[] toUTF8ByteArray()
byte array,
using the UTF-8 character encoding.
byte array is
cleared after use.public byte[] toUSASCIIByteArray()
byte array,
using the US-ASCII character encoding.
Sun states that any implementation of the Java 2 platform, Standard Edition, v. 1.3 or higher is required to support this encoding.
byte array is
cleared after use.public byte[] toISO88591ByteArray()
byte array,
using the ISO-8859-1 character encoding.
Sun states that any implementation of the Java 2 platform, Standard Edition, v. 1.3 or higher is required to support this encoding.
byte array is
cleared after use.public byte[] toByteArray(java.lang.String enc)
throws java.io.UnsupportedEncodingException
byte array,
using the specified character encoding.
byte array is
cleared after use.enc - the name of the character encodingjava.io.UnsupportedEncodingException - thrown if the character encoding is not supportedpublic char[] toCharArray()
public SecureByteArray toSecureByteArray()
SecureStringBuffer to a
SecreByteArray using the default character encoding.
The method performs the transformation from SecureStringBuffer
to SecreByteArray by creating a copy of the data.
SecureStringBuffer is not wiped following
this call, leaving two secure copies of the data in memory. Use
the wipe() method if you want to clear the original
SecureStringBuffer from memory.public SecureByteArray toSecureByteArray(java.lang.String enc) throws java.io.UnsupportedEncodingException
SecureStringBuffer to a
SecreByteArray using the specified character encoding.
The method performs the transformation from SecureStringBuffer
to SecreByteArray by creating a copy of the data.
SecureStringBuffer is not wiped following
this call, leaving two secure copies of the data in memory. Use
the wipe() method if you want to clear the original
SecureStringBuffer from memory.enc - the name of the character encodingjava.io.UnsupportedEncodingException - thrown if the character encoding is not supportedpublic java.lang.String toString()
String.
String, a copy
of the data, which cannot be destroyed, is placed in memory. The
String continues to represent the sensitive data until
it is garbage-collected and overwritten by other data.toString in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
Two SecureStringBuffer objects are equal only if the sensitive
data (textbyte arrays) they represent are equal.
equals in class java.lang.Objectobj - the reference object with which to comparetrue if the objects are "equal"; false
otherwisepublic void wipe()
SecureStringBuffer.
Use this method rather than the finalize method to clear the
memory.