Package org.owasp.esapi.crypto
Class PlainText
- java.lang.Object
-
- org.owasp.esapi.crypto.PlainText
-
- All Implemented Interfaces:
java.io.Serializable
public final class PlainText extends java.lang.Object implements java.io.SerializableA class representing plaintext (versus ciphertext) as related to cryptographic systems. This class embodies UTF-8 byte-encoding to translate between byte arrays andStrings. 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 anUnsupportedEncodingExceptionnever actually be thrown. Therefore, in order to to keep client code uncluttered, any possibleUnsupportedEncodingExceptions will be first logged, and then re-thrown as aRuntimeExceptionwith the originalUnsupportedEncodingExceptionas the cause.Copyright © 2009 - The OWASP Foundation
- Since:
- 2.0
- Author:
- kevin.w.wall@gmail.com
- See Also:
CipherText, Serialized Form
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]asBytes()Convert thePlainTextobject to a byte array.protected booleancanEqual(java.lang.Object other)Needed for correct definition of equals for general classes.booleanequals(java.lang.Object anObject)inthashCode()Same asthis.toString().hashCode().intlength()Return the length of the UTF-8 encoded byte array representing this object.voidoverwrite()First overwrite the bytes of plaintext with the character '*'.java.lang.StringtoString()Convert thePlainTextobject to a UTF-8 encodedString.
-
-
-
Constructor Detail
-
PlainText
public PlainText(java.lang.String str)
Construct aPlainTextobject from aString.- Parameters:
str- TheStringthat is converted to a UTF-8 encoded byte array to create thePlainTextobject.- Throws:
java.lang.IllegalArgumentException- Ifstrargument is null.
-
PlainText
public PlainText(byte[] b)
Construct aPlainTextobject from abytearray.- Parameters:
b- Thebytearray used to create thePlainTextobject.
-
-
Method Detail
-
toString
public java.lang.String toString()
Convert thePlainTextobject to a UTF-8 encodedString.- Overrides:
toStringin classjava.lang.Object- Returns:
- A
Stringrepresenting thePlainTextobject.
-
asBytes
public byte[] asBytes()
Convert thePlainTextobject to a byte array.- Returns:
- A byte array representing the
PlainTextobject.
-
equals
public boolean equals(java.lang.Object anObject)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
Same asthis.toString().hashCode().- Overrides:
hashCodein classjava.lang.Object- Returns:
this.toString().hashCode().
-
length
public int length()
Return the length of the UTF-8 encoded byte array representing this object. Note that if this object was constructed with the constructorPlainText(String str), then this length might not necessarily agree withstr.length().- Returns:
- The length of the UTF-8 encoded byte array representing this object.
-
overwrite
public void overwrite()
First overwrite the bytes of plaintext with the character '*'.
-
canEqual
protected boolean canEqual(java.lang.Object other)
Needed for correct definition of equals for general classes. (Technically not needed for 'final' classes though like this class though; this will just allow it to work in the future should we decide to allow * sub-classing of this class.)See How to write an Equality Method in Java for full explanation.
-
-