public class SecureByteArray extends Object
It's a very bad idea to store passwords in a java.lang.String object because once that object is created, you cannot guarantee that the contents will be erased. You can't get at the actual bytes inside the String object. Thus you cannot reset all the bytes to 0.
This object stores a plain array of bytes allowing the data to be erased back to 0 at any given time.
ALWWAYS reset your password storage variables when you are through with them and be very wary of the stack.
| Modifier | Constructor and Description |
|---|---|
|
SecureByteArray() |
|
SecureByteArray(byte[] bytes) |
|
SecureByteArray(char[] chars) |
protected |
SecureByteArray(char[] chars,
boolean encodeUTF8) |
|
SecureByteArray(int size) |
|
SecureByteArray(SecureByteArray copy) |
|
SecureByteArray(SecureUTF8String str) |
|
SecureByteArray(String str)
Creates the object from a string (don't pass passwords in this way).
|
| Modifier and Type | Method and Description |
|---|---|
void |
append(SecureByteArray arr)
Appends another SecureByteArray to this one.
|
void |
erase()
Erases the data in this array by writing a pattern over every element
of the array.
|
byte |
getByteAt(int index)
Obtains the byte at an index.
|
byte[] |
getData()
Returns a reference to the data.
|
void |
prepend(SecureByteArray arr)
Prepends this array with another SecureByteArray.
|
void |
replace(SecureByteArray arr)
Replaces the contents of this array with a copy of those in arr, resizing
the array as needed.
|
void |
resize(int size,
boolean retainData)
Resizes the array, optionally keeping the old data.
|
void |
setByteAt(int index,
byte c)
Sets the byte at an index.
|
int |
size()
Gets the size of this array.
|
public SecureByteArray()
public SecureByteArray(int size)
public SecureByteArray(byte[] bytes)
public SecureByteArray(char[] chars)
protected SecureByteArray(char[] chars,
boolean encodeUTF8)
public SecureByteArray(SecureByteArray copy)
public SecureByteArray(String str)
str - The string object to get the data from.public SecureByteArray(SecureUTF8String str)
public void append(SecureByteArray arr) throws Exception
arr - The array to append.Exception - Upon size problems. (lol)public void erase()
The pattern part probably isn't needed and probably doesn't do anything but it's there anyway. The important part is to reset all the elements back to 0.
public byte getByteAt(int index)
throws ArrayIndexOutOfBoundsException
index - The index to obtain the byte at.ArrayIndexOutOfBoundsException - Upon bad index.public byte[] getData()
public void prepend(SecureByteArray arr) throws Exception
arr - The array to prepend.Exception - Upon size problems. (lol)public void replace(SecureByteArray arr) throws Exception
arr - The copy to use.Exception - on exceptionpublic void resize(int size,
boolean retainData)
throws Exception
size - The new size of the array. This must be 1 or larger.retainData - Whether or not to keep the old data.Exception - If the size is 0 or less.public void setByteAt(int index,
byte c)
throws ArrayIndexOutOfBoundsException
index - The index to set at.c - The byte to set.ArrayIndexOutOfBoundsException - Upon bad index.public int size()
Copyright © 2018. All rights reserved.