public class SecureByteArray
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable
Application programmers do not usually have to consider how to destroy a
SecureByteArray passed within the Toolkit most methods
automatically wipe, or destroy, the SecureByteArray object
once it is no longer needed. This class includes a wipe()
method to destroy SecureByteArray 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 protect the data
|
static int |
HIGH
High sensitivity - encrypt the data
|
static int |
MEDIUM
Medium sensitivity - xor the data
|
| Constructor and Description |
|---|
SecureByteArray(byte[] ba)
Creates a new
SecureByteArray from the given byte array. |
SecureByteArray(byte[] ba,
int sensitivity)
Creates a new
SecureByteArray from the given byte array and
using the specified sensitivity. |
SecureByteArray(java.io.InputStream is)
Creates a new
SecureByteArray by reading the sensitive data
from an InputStream. |
SecureByteArray(java.io.InputStream is,
int sensitivity)
Creates a new
SecureByteArray by reading the sensitive data
from an InputStream. |
SecureByteArray(SecureByteArray sba)
The copy constructor used to create a new instance of
SecureByteArray that is identical to the specified
SecureByteArray. |
| Modifier and Type | Method and Description |
|---|---|
java.lang.Object |
clone()
Returns a clone of the
SecureByteArray. |
boolean |
equals(java.lang.Object obj)
Indicates whether some other object is "equal to" this one.
|
byte[] |
getByteArray()
Returns a copy of the sensitive data as a
byte array. |
int |
getSensitivity()
Returns the sensitivity for this
SecureByteArray object. |
byte[] |
toByteArray()
Returns a copy of the sensitive data as a
byte array. |
void |
wipe()
Clears the sensitive data held as a
SecureByteArray. |
public static final int BASE
public static final int MEDIUM
public static final int HIGH
public SecureByteArray(byte[] ba)
SecureByteArray from the given byte array.
After the SecureByteArray has been initialized, the
byte array passed in as an argument is wiped from memory.
The sensitivity is set to the default value BASE.
ba - the byte array holding the sensitive datajava.lang.IllegalArgumentException - thrown if the byte array is nulljava.lang.SecurityException - thrown when MEDIUM> or HIGH sensitivity is
used and the Entrust cryptographic service provider is not installedpublic SecureByteArray(byte[] ba,
int sensitivity)
SecureByteArray from the given byte array and
using the specified sensitivity.
After the SecureByteArray has been initialized, the
byte array passed in as an argument is wiped from memory.
ba - the byte array holding the sensitive datasensitivity - sensitivity of the datajava.lang.IllegalArgumentException - thrown if the byte array is nulljava.lang.SecurityException - thrown when MEDIUM> or HIGH sensitivity is
used and the Entrust cryptographic service provider is not installedpublic SecureByteArray(java.io.InputStream is)
throws java.io.IOException
SecureByteArray by reading the sensitive data
from an InputStream.
The sensitivity is set to the default value BASE.
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 nulljava.lang.SecurityException - thrown when MEDIUM> or HIGH sensitivity is
used and the Entrust cryptographic service provider is not installedpublic SecureByteArray(java.io.InputStream is,
int sensitivity)
throws java.io.IOException
SecureByteArray by reading the sensitive data
from an InputStream.
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 readsensitivity - sensitivity of the datajava.io.IOException - thrown if a problem occurs while reading the InputStreamjava.lang.IllegalArgumentException - thrown if the input stream is nulljava.lang.SecurityException - thrown when MEDIUM> or HIGH sensitivity is
used and the Entrust cryptographic service provider is not installedpublic SecureByteArray(SecureByteArray sba)
SecureByteArray that is identical to the specified
SecureByteArray.
SecureByteArray argument. If necessary, you can do
this by calling the wipe method on the argument.sba - the secure byte array to be copiedjava.lang.IllegalArgumentException - thrown if the secure byte array is nulljava.lang.SecurityException - thrown when MEDIUM> or HIGH sensitivity is
used and the Entrust cryptographic service provider is not installedpublic java.lang.Object clone()
SecureByteArray.
clone in class java.lang.Objectpublic int getSensitivity()
SecureByteArray object.
public byte[] getByteArray()
byte array.
byte array is
cleared after use.java.lang.SecurityException - thrown when HIGH sensitivity is used and the Entrust
cryptographic service provider is not installedpublic byte[] toByteArray()
byte array.
byte array is
cleared after use.java.lang.SecurityException - thrown when HIGH sensitivity is used and the Entrust
cryptographic service provider is not installedpublic boolean equals(java.lang.Object obj)
Two SecureByteArray objects are equal only if the sensitive
data (byte data) 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()
SecureByteArray.
This method overwrites memory held by the sensitive data with bytes 0x00
and then sets the sensitive data to equal a new byte array of length zero.
It also sets the sensitivity to -1, so that there is no way to tell how
the data was originally protected. Use this method rather than
finalize() to clear memory.