|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.emory.mathcs.util.security.CharStrings
Utility methods to securely manipulate on character arrays. The methods allow to treat the character arrays similarly to strings, yet they ensure that all temporary arrays are zeroed-out before discarding.
Application of this class stems from the fact that String class is not appropriate for holding passwords and other sensitive information. Strings cannot be zeroed-out before unreferencing, thus the content may be dangling in memory for quite a while before it is garbage-collected, and it can stay in the process data block even longer, until it is overwritten. It has been demonstrated that attacker can obtain the data in clear text by forcing the operating system to swap out the application in question, and then by reading the swap file. To minimize the risk, sensitive data should be cleared explicitly as soon as possible. It suggests using mutable character arrays in favor of strings. This class allows to operate on such arrays much like on strings, in particular, it provides methods to securely concatenate them, as well as write them to, and read them from streams in the UTF format.
Method Summary | |
static void |
clear(char[] s)
Zeroes-out the specified character array. |
static char[] |
concat(char[] s1,
char[] s2)
Returns a concatenation of two character arrays. |
static boolean |
equals(char[] s1,
char[] s2)
Compares two character arrays. |
static char[] |
fromUTF(byte[] utfString)
Recovers a character array out of its UTF-8 encoding. |
static char[] |
fromUTF(byte[] utfString,
int off,
int len)
Recovers a character array out of its UTF-8 encoding. |
static int |
getUTFLen(char[] s,
int off,
int len)
Returns the number of bytes of an UTF-8 encoding of a portion of the specified character array. |
static char[] |
readUTF(java.io.DataInput in)
Reads UTF-8 encoded character array from a data input. |
static char[] |
readUTF(java.io.InputStream in)
Reads UTF-8 encoded character array from an input stream. |
static byte[] |
toUTF(char[] s)
Converts the specified character array into its UTF-8 encoding. |
static byte[] |
toUTF(char[] s,
int off,
int len)
Converts a portion of the specified character array into its UTF-8 encoding. |
static int |
writeUTF(java.io.OutputStream out,
char[] s)
Writes the specified character array to the output stream using UTF-8 encoding. |
static int |
writeUTF(java.io.OutputStream out,
char[] s,
int off,
int len)
Writes a portion of the specified character array to the output stream using UTF-8 encoding. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
public static char[] concat(char[] s1, char[] s2)
s1
- first arrays2
- second array
public static boolean equals(char[] s1, char[] s2)
s1
- first arrays2
- second array
public static void clear(char[] s)
s
- the array to zero-outpublic static int writeUTF(java.io.OutputStream out, char[] s) throws java.io.IOException
out
- the output to write tos
- array to write to
java.io.IOException
- if I/O error occurspublic static int writeUTF(java.io.OutputStream out, char[] s, int off, int len) throws java.io.IOException
out
- the output to write tos
- array to write tooff
- start offset within slen
- number of characters to write
java.io.IOException
- if I/O error occurspublic static byte[] toUTF(char[] s)
s
- the array to encode
public static byte[] toUTF(char[] s, int off, int len)
s
- the array to encodeoff
- the start offset within slen
- the number of characters to encode
public static int getUTFLen(char[] s, int off, int len)
s
- the character arrayoff
- the start offset within slen
- the number of characters to include
public static final char[] readUTF(java.io.InputStream in) throws java.io.IOException
in
- the input stream to read from
java.io.IOException
- if I/O error occurspublic static final char[] readUTF(java.io.DataInput in) throws java.io.IOException
in
- the data input to read from
java.io.IOException
- if I/O error occurspublic static final char[] fromUTF(byte[] utfString) throws java.io.IOException
utfString
- containing UTF-8-encoded character array
java.io.IOException
- if I/O error occurspublic static final char[] fromUTF(byte[] utfString, int off, int len) throws java.io.IOException
utfString
- array containing UTF-8-encoded character arrayoff
- start offset within utfStringlen
- number of bytes to include
java.io.IOException
- if I/O error occurs
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |