public final class PlainText
extends java.lang.Object
implements java.io.Serializable
Strings. Once constructed, this
object is immutable.
Note: Conversion to/from UTF-8 byte-encoding can, in theory, throw
an UnsupportedEncodingException. However, UTF-8 encoding
should be a standard encoding for all Java installations, so an
UnsupportedEncodingException never actually be thrown. Therefore,
in order to to keep client code uncluttered, any possible
UnsupportedEncodingExceptions will be first logged, and then
re-thrown as a RuntimeException with the original
UnsupportedEncodingException as the cause.
Copyright © 2009 - The OWASP Foundation
CipherText,
Serialized Form| Modifier and Type | Field and Description |
|---|---|
private static Logger |
logger |
private byte[] |
rawBytes |
private static long |
serialVersionUID |
| Constructor and Description |
|---|
PlainText(byte[] b)
Construct a
PlainText object from a byte array. |
PlainText(java.lang.String str)
Construct a
PlainText object from a String. |
| Modifier and Type | Method and Description |
|---|---|
byte[] |
asBytes()
Convert the
PlainText object to a byte array. |
protected boolean |
canEqual(java.lang.Object other)
Needed for correct definition of equals for general classes.
|
boolean |
equals(java.lang.Object anObject) |
int |
hashCode()
Same as
this.toString().hashCode(). |
int |
length()
Return the length of the UTF-8 encoded byte array representing this
object.
|
void |
overwrite()
First overwrite the bytes of plaintext with the character '*'.
|
java.lang.String |
toString()
Convert the
PlainText object to a UTF-8 encoded String. |
private static final long serialVersionUID
private static Logger logger
private byte[] rawBytes
public PlainText(java.lang.String str)
PlainText object from a String.str - The String that is converted to a UTF-8 encoded
byte array to create the PlainText object.java.lang.IllegalArgumentException - If str argument is null.public PlainText(byte[] b)
PlainText object from a byte array.b - The byte array used to create the PlainText
object.public java.lang.String toString()
PlainText object to a UTF-8 encoded String.toString in class java.lang.ObjectString representing the PlainText object.public byte[] asBytes()
PlainText object to a byte array.PlainText object.public boolean equals(java.lang.Object anObject)
equals in class java.lang.Objectpublic int hashCode()
this.toString().hashCode().hashCode in class java.lang.Objectthis.toString().hashCode().public int length()
PlainText(String str), then this length might not necessarily
agree with str.length().public void overwrite()
protected boolean canEqual(java.lang.Object other)
See How to write an Equality Method in Java for full explanation.