|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.wicket.util.crypt.Base64
public class Base64
Provides Base64 encoding and decoding with URL and filename safe alphabet as defined by RFC 3548, section 4.
This Base64 encoder is modified to meet URL requirements. The changes are: '+' => '*', '/' => '-', and no padding. This class is taken from the Apache commons-codec, and adjusted to fit the Wicket framework's needs, especially external dependencies have been removed. This class implements section 4. Base 64 Encoding with URL and Filename Safe Alphabet from RFC 3548 The Base16, Base32, and Base64 Data Encodings by Simon Josefsson.
Constructor Summary | |
---|---|
Base64()
Creates a Base64 codec used for decoding (all modes) and encoding in URL-unsafe mode. |
|
Base64(boolean urlSafe)
Creates a Base64 codec used for decoding (all modes) and encoding in the given URL-safe mode. |
|
Base64(int lineLength)
Creates a Base64 codec used for decoding (all modes) and encoding in URL-unsafe mode. |
|
Base64(int lineLength,
byte[] lineSeparator)
Creates a Base64 codec used for decoding (all modes) and encoding in URL-unsafe mode. |
|
Base64(int lineLength,
byte[] lineSeparator,
boolean urlSafe)
Creates a Base64 codec used for decoding (all modes) and encoding in URL-unsafe mode. |
Method Summary | |
---|---|
byte[] |
decode(byte[] pArray)
Decodes a byte[] containing containing characters in the Base64 alphabet. |
byte[] |
decode(java.lang.String pArray)
Decodes a String containing containing characters in the Base64 alphabet. |
static byte[] |
decodeBase64(byte[] base64Data)
Decodes Base64 data into octets |
static byte[] |
decodeBase64(java.lang.String base64String)
Decodes a Base64 String into octets |
static java.math.BigInteger |
decodeInteger(byte[] pArray)
Decodes a byte64-encoded integer according to crypto standards such as W3C's XML-Signature |
byte[] |
encode(byte[] pArray)
Encodes a byte[] containing binary data, into a byte[] containing characters in the Base64 alphabet. |
static byte[] |
encodeBase64(byte[] binaryData)
Encodes binary data using the base64 algorithm but does not chunk the output. |
static byte[] |
encodeBase64(byte[] binaryData,
boolean isChunked)
Encodes binary data using the base64 algorithm, optionally chunking the output into 76 character blocks. |
static byte[] |
encodeBase64(byte[] binaryData,
boolean isChunked,
boolean urlSafe)
Encodes binary data using the base64 algorithm, optionally chunking the output into 76 character blocks. |
static byte[] |
encodeBase64(byte[] binaryData,
boolean isChunked,
boolean urlSafe,
int maxResultSize)
Encodes binary data using the base64 algorithm, optionally chunking the output into 76 character blocks. |
static byte[] |
encodeBase64Chunked(byte[] binaryData)
Encodes binary data using the base64 algorithm and chunks the encoded output into 76 character blocks |
static java.lang.String |
encodeBase64String(byte[] binaryData)
Encodes binary data using the base64 algorithm into 76 character blocks separated by CRLF. |
static byte[] |
encodeBase64URLSafe(byte[] binaryData)
Encodes binary data using a URL-safe variation of the base64 algorithm but does not chunk the output. |
static java.lang.String |
encodeBase64URLSafeString(byte[] binaryData)
Encodes binary data using a URL-safe variation of the base64 algorithm but does not chunk the output. |
static byte[] |
encodeInteger(java.math.BigInteger bigInt)
Encodes to a byte64-encoded integer according to crypto standards such as W3C's XML-Signature |
java.lang.String |
encodeToString(byte[] pArray)
Encodes a byte[] containing binary data, into a String containing characters in the Base64 alphabet. |
static boolean |
isArrayByteBase64(byte[] arrayOctet)
Tests a given byte array to see if it contains only valid characters within the Base64 alphabet. |
static boolean |
isBase64(byte octet)
Returns whether or not the octet is in the base 64 alphabet. |
boolean |
isUrlSafe()
Returns our current encode mode. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Base64()
When encoding the line length is 76, the line separator is CRLF, and the encoding table is STANDARD_ENCODE_TABLE.
When decoding all variants are supported.
public Base64(boolean urlSafe)
When encoding the line length is 76, the line separator is CRLF, and the encoding table is STANDARD_ENCODE_TABLE.
When decoding all variants are supported.
urlSafe
- if true
, URL-safe encoding is used. In most cases this should be set
to false
.public Base64(int lineLength)
When encoding the line length is given in the constructor, the line separator is CRLF, and the encoding table is STANDARD_ENCODE_TABLE.
Line lengths that aren't multiples of 4 will still essentially end up being multiples of 4 in the encoded data.
When decoding all variants are supported.
lineLength
- Each line of encoded data will be at most of the given length (rounded down to
nearest multiple of 4). If lineLength <= 0, then the output will not be divided
into lines (chunks). Ignored when decoding.public Base64(int lineLength, byte[] lineSeparator)
When encoding the line length and line separator are given in the constructor, and the encoding table is STANDARD_ENCODE_TABLE.
Line lengths that aren't multiples of 4 will still essentially end up being multiples of 4 in the encoded data.
When decoding all variants are supported.
lineLength
- Each line of encoded data will be at most of the given length (rounded down to
nearest multiple of 4). If lineLength <= 0, then the output will not be divided
into lines (chunks). Ignored when decoding.lineSeparator
- Each line of encoded data will end with this sequence of bytes.
java.lang.IllegalArgumentException
- Thrown when the provided lineSeparator included some base64 characters.public Base64(int lineLength, byte[] lineSeparator, boolean urlSafe)
When encoding the line length and line separator are given in the constructor, and the encoding table is STANDARD_ENCODE_TABLE.
Line lengths that aren't multiples of 4 will still essentially end up being multiples of 4 in the encoded data.
When decoding all variants are supported.
lineLength
- Each line of encoded data will be at most of the given length (rounded down to
nearest multiple of 4). If lineLength <= 0, then the output will not be divided
into lines (chunks). Ignored when decoding.lineSeparator
- Each line of encoded data will end with this sequence of bytes.urlSafe
- Instead of emitting '+' and '/' we emit '-' and '_' respectively. urlSafe is only
applied to encode operations. Decoding seamlessly handles both modes.
java.lang.IllegalArgumentException
- The provided lineSeparator included some base64 characters. That's not going to
work!Method Detail |
---|
public boolean isUrlSafe()
public static boolean isBase64(byte octet)
octet
is in the base 64 alphabet.
octet
- The value to test
true
if the value is defined in the the base 64 alphabet,
false
otherwise.public static boolean isArrayByteBase64(byte[] arrayOctet)
arrayOctet
- byte array to test
true
if all bytes are valid characters in the Base64 alphabet or if the
byte array is empty; false, otherwisepublic static byte[] encodeBase64(byte[] binaryData)
binaryData
- binary data to encode
public static java.lang.String encodeBase64String(byte[] binaryData)
binaryData
- binary data to encode
public static byte[] encodeBase64URLSafe(byte[] binaryData)
binaryData
- binary data to encode
public static java.lang.String encodeBase64URLSafeString(byte[] binaryData)
binaryData
- binary data to encode
public static byte[] encodeBase64Chunked(byte[] binaryData)
binaryData
- binary data to encode
public byte[] decode(java.lang.String pArray)
pArray
- A String containing Base64 character data
public byte[] decode(byte[] pArray)
pArray
- A byte array containing Base64 character data
public static byte[] encodeBase64(byte[] binaryData, boolean isChunked)
binaryData
- Array containing binary data to encode.isChunked
- if true
this encoder will chunk the base64 output into 76 character
blocks
java.lang.IllegalArgumentException
- Thrown when the input array needs an output array bigger than
Integer.MAX_VALUE
public static byte[] encodeBase64(byte[] binaryData, boolean isChunked, boolean urlSafe)
binaryData
- Array containing binary data to encode.isChunked
- if true
this encoder will chunk the base64 output into 76 character
blocksurlSafe
- if true
this encoder will emit - and _ instead of the usual + and /
characters.
java.lang.IllegalArgumentException
- Thrown when the input array needs an output array bigger than
Integer.MAX_VALUE
public static byte[] encodeBase64(byte[] binaryData, boolean isChunked, boolean urlSafe, int maxResultSize)
binaryData
- Array containing binary data to encode.isChunked
- if true
this encoder will chunk the base64 output into 76 character
blocksurlSafe
- if true
this encoder will emit - and _ instead of the usual + and /
characters.maxResultSize
- The maximum result size to accept.
java.lang.IllegalArgumentException
- Thrown when the input array needs an output array bigger than maxResultSizepublic static byte[] decodeBase64(java.lang.String base64String)
base64String
- String containing Base64 data
public static byte[] decodeBase64(byte[] base64Data)
base64Data
- Byte array containing Base64 data
public java.lang.String encodeToString(byte[] pArray)
pArray
- a byte array containing binary data
public byte[] encode(byte[] pArray)
pArray
- a byte array containing binary data
public static java.math.BigInteger decodeInteger(byte[] pArray)
pArray
- a byte array containing base64 character data
public static byte[] encodeInteger(java.math.BigInteger bigInt)
bigInt
- a BigInteger
java.lang.NullPointerException
- if null is passed in
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |